使用docker部署MySQL服务器

1.下载MySQL的镜像

$ docker pull mysql/mysql-server:latest

2.创建并启动MySQL服务容器

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server

此时,navicate客户端连接mysql报错:Client does not support authentication protocol requested by server

3.连接MySQL数据库

docker exec -it mysql bash
bash-4.2# mysql -u root -p 123456
#授权
mysql>CREATE USER 'root'@'%' IDENTIFIED BY 'root';
mysql>GRANT ALL ON *.* TO 'root'@'%';
#刷新权限
mysql> flush privileges;
#修改root用户密码
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
#刷新权限
mysql> flush privileges;

4.navicate客户端连接MySQL服务器

发现执行ddl语句报错 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'inform
修改sql_mode

vi /etc/my.cnf
bash: vi: command not found
#安装vi
bash-4.2# yum install vi
vi /etc/my.cnf
#在[mysqld]下面添加
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
#重启mysql服务
docker restart mysql

你可能感兴趣的:(使用docker部署MySQL服务器)