环境:MAC,MySQL版本:8.0.30
1、安装mysql,执行命令:
sudo rm -rf /var/db/receipts/com.mysql.*
2、建立容器,执行命令:
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.30
3、查看容器ID,执行命令:
docker ps
4、进入容器内部,执行命令:
docker exec -it cd3457645fa3 /bin/bash
5、在容器内部用mysql命令连接mysql:
mysql -uroot -p123456
6、查看mysql权限:
select user,host,plugin from mysql.user;
7、 修改mysql访问权限:
update user set host = '%' where user = 'root';
8、刷新权限:
flush privileges;
9、修改密码认证配置:
ALTER user 'root'@'%'IDENTIFIED WITH mysql_native_password BY '123456'; (123456则是root连接密码)
若修改root还是连接不成功,可修改完下面所有的user试试:
alter user 'mysql.infoschema'@'localhost' identified with mysql_native_password by '123456';
alter user 'mysql.session'@'localhost' identified with mysql_native_password by '123456';
alter user 'mysql.sys'@'localhost' identified with mysql_native_password by '123456';
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
现在,即可用Navicat正常连接mysql了!
另外,卸载本机安装的MYSQL命令:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
文章来源地址https://www.toymoban.com/news/detail-594891.html文章来源:https://www.toymoban.com/news/detail-594891.html
到了这里,关于用Docker运行MYSQL并连接的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!