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;
尝试过,可行。