Docker 运行 Mysql 在 Mysql workbench 无法连接
docker run --name mysql-server -p 3306:3306 -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=bei!123 -d mysql
Docker MySql Error:Access denied for user 'root'@'localhost' (using password: YES)
解决方案:
- sudo mkdir /usr/local/mysql
- sudo mkdir /usr/local/mysql/data
- sudo mkdir /usr/local/mysql/conf.d
- docker run --name mysql-server -p 3306:3306 -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=bei!123 -d mysql
- touch /usr/local/mysql/conf.d/my.cnf
sudo gedit /usr/local/mysql/conf.d/my.cnf, and type in below:
[mysqld] skip-grant-tables
- docker restart [mysql container id]
- docker exec -it [mysql container id] bash
- mysql -uroot -p
- grant all privileges on . to 'root'@'%' identified by 'bei!123';
- select user,authentication_string,host from user;
- update user set authentication_string='' where user='root';
- flush privileges;
- quit mysql ctrl d d
- sudo gedit /usr/local/mysql/conf.d/my.cnf
- delete 'skip-grant-tables'
- docker restart [mysql container id]
- docker exec -it [mysql container id] bash
- mysql -uroot -p (密码是回车)
- use mysql;
- alter user 'root'@'localhost' IDENTIFIED BY 'bei!123';
- alter user 'root'@'%' IDENTIFIED BY 'beya!123';
- flush privileges;
- GRANT all ON . TO 'root'@'%' IDENTIFIED BY 'bei!123';
- flush privileges;
尝试过,可行。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。