文章目录

1. 安装mysql
# 通过搜索镜像
docker search mysql

# 拉取mysql镜像
docker pull mysql

# 查看拉取的mysql镜像
docker images

#创建MySQL容器
docker run -di --name mymysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql

# 查看mysql容器是否启动运行
docker ps

# 进入MySQL容器,登陆MySQL
docker exec -it mymysql /bin/bash

# 登陆mysql
mysql -uroot -p

# 输入密码即可登陆成功


# 修改root用户允许远程访问
alter user 'root'@'%' identified with mysql_native_password by 'root';

# 开放防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent

# 重启防火墙
2. Navicat Premium 远程连接

docker 安装 mysql和Navicat Premium 远程连接_docker


docker 安装 mysql和Navicat Premium 远程连接_oracle_02


docker 安装 mysql和Navicat Premium 远程连接_mysql_03

操作记录

[root@localhost ~]# docker run -di --name mymysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql
fa98844ab9db1a50a836520804a83ff584ebff1f4e90bb204a4b7ff70cd45227
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fa98844ab9db mysql "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 0.0.0.0:3306->3306/tcp, 33060/tcp mymysql

[root@localhost ~]# docker exec -it mymysql /bin/bash
root@fa98844ab9db:/# mysql -uroot -p
Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'%' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
root@fa98844ab9db:/# exit
exit
[root@localhost ~]#