docker安装mysql

docker安装mysql8.0.18

1.docker pull mysql:8.0.18,https://hub.docker.com/_/mysql?tab=tags这是mysql地址
2.docker run --name mysql -p 3306:3306 --restart=always -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.18
注:–restart=always 表示,该容器随docker服务启动而自动启动
报错①:docker: Error response from daemon: driver failed programming external connectivity on endpoint mysql (1e6713f2c46480efb28a3bb43db54b6a2bbfdf0f26c4f5326e496bdc1505a76a): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use.
解决办法:查看端口是否被占用,命令:netstat -nap | grep 3306,然后kill PID 杀死该进程 ,这里是kill 2313
在这里插入图片描述

报错②:Error response from daemon: Conflict. The container name "/mysql" is already in use by container "b12ba1f2ef08ed4737ab93ebea6d100fd27288c781859138fe47b84895dd050b". You have to remove (or rename) that container to be able to reuse that name.
解决办法:输入docker ps -a 查看所有实例运行,然后docker rm b12ba1f2ef08删除实例。
在这里插入图片描述

重新启动,docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.18。启动成功后,进入容器:docker exec -it mysql bash,登录mysql:mysql -u root -p,然后输入:ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';,添加远程登录用户:

CREATE USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
授权:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

windows上登录mysql,
docker安装mysql_第1张图片
重启mysql命令:

docker ps -a
docker restart CONTAINERID

你可能感兴趣的:(docker,java,html,xml)