docker 部署mysql数据库
拉取镜像
docker pull mysql
查看是否镜像拉取成功
docker images
[root@sulong ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 4f06b49211c0 3 days ago 530MB
为启动容器做准备
创建相对应的容器卷(我的目录是下面这样的)
[root@sulong mysql]# pwd
/home/data/mysql
[root@sulong mysql]# ll
total 16
drwxr-xr-x 3 root root 4096 Feb 27 16:33 conf
drwxr-xr-x 7 systemd-coredump root 4096 Feb 27 16:41 data
drwxr-xr-x 2 root root 4096 Feb 27 16:33 logs
drwxr-xr-x 2 root root 4096 Feb 27 16:33 my.cnf
[root@sulong mysql]#
启动容器命令
docker run --restart=always --privileged=true
-v /home/data/mysql/data/:/var/lib/mysql
-v /home/data/mysql/logs/:/var/log/mysql
-v /home/data/mysql/conf:/etc/mysql/conf
-v /home/data/mysql/my.cnf:/etc/mysql/my.cnf
-p 33061:3306 --name mysql
-e MYSQL_ROOT_PASSWORD=2445959102sx -d mysql
查看启动日志
docker logs [容器id或者容器的名称]
[root@sulong my.cnf]# docker logs mysql
2023-02-27 09:11:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
2023-02-27 09:11:11+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2023-02-27 09:11:11+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.32-1.el8 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2023-02-27T09:11:11.678554Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-02-27T09:11:11.680481Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
2023-02-27T09:11:11.688035Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-27T09:11:12.248075Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-27T09:11:12.583054Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-02-27T09:11:12.583094Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-02-27T09:11:12.588066Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2023-02-27T09:11:12.617632Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
2023-02-27T09:11:12.617688Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
Navicat链接测试