1、创建实例命令
docker run -id –name=c_mysql -p 3306:3306 -v /docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.6.37
2、查看启动的实例 docker ps
3、这里映射的是宿主机的3306端口,我已经把端口开放了
4、在宿主机进行连接
#这个报错像是mysql不存在,查看mysql是否启动
#mysql已启动,端口也没有被占用
5、已经在容器里面测试了,mysql可以正常连接;在试试将root用户开放可以任何主机访问
5.1、进入容器,并连接mysql
docker exec -it c_mysql bash
mysql -uroot -p123456
5.2、将root用户开放所有主机可以访问
mysql> grant all privileges on . to root@‘%’; #授权
mysql> flush privile
原文链接:https://blog.csdn.net/m0_67402914/article/details/126099388?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836884016800180645872%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836884016800180645872&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-9-126099388-null-null.nonecase&utm_term=docker%E9%83%A8%E7%BD%B2