Linux环境下,宿主机连接docker容器中运行的mysql数据库

apt -y install docker.io
docker pull mysql:5.6
docker run -it -p 33060:3306 –-name mysql –restart=always mysql:5.6 bash
docker exec -it “id” bash
进入容器:
/etc/init.d/mysql start
mysql <进入数据库>
create database uos;
create user uos identified by ‘uos’;
use mysql
mysql> update user set password=password(‘uos’) where user=’root’;
mysql> update user set plugin=’’ where user=’root’;
mysql> grant all privileges on . to ‘root’@’%’ identified by ‘uos’ with
grant option;
mysql> flush privileges;
exit
/etc/init.d/mysql restart
验证:mysql -h 172.17.0.1 -P33060 -uroot -puos
备注:此时如果连接不成功执行如下步骤:
docker exec -it “id” bash 进入容器
/etc/init.d/mysql restart
exit
再次进行验证:
mysql -h 172.17.0.1 -P33060 -uroot -puos

你可能感兴趣的:(docker,mysql)