Docker——Mysql部署
通过docker容器化部署mysql
1.部署mysql
(1)执行命令部署mysql
docker run -v /work/mysql/:/var/lib/mysql \
-p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 \
--restart=always --name mysql -d mysql
执行成功的情况如下
[root@node1 ~]# docker run -v /work/mysql/:/var/lib/mysql \
> -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 \
> --restart=always --name mysql -d mysql
Unable to find image 'mysql:latest' locally
latest: Pulling from library/mysql
72a69066d2fe: Pull complete
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d81c0153429607251656806cc784e914937271037f7738bd5b8e7709
Status: Downloaded newer image for mysql:latest
2e0e6049e41b9d8bc2ba839bca4251ad333613c135cf0eb92a90abeeca5bb6b4
备注:
(1)数据库文件直接挂载到服务器的 /work/mysql/ 目录下
(2)端口号使用默认的3306,root密码是 123456
2.检查执行情况
执行 ls /work/mysql 命令,查看 /work/mysql/ 目录的数据库文件
[root@node1 ~]# ls /work/mysql
auto.cnf binlog.index client-cert.pem #ib_16384_1.dblwr ib_logfile0 #innodb_temp performance_schema server-cert.pem undo_001
binlog.000001 ca-key.pem client-key.pem ib_buffer_pool ib_logfile1 mysql private_key.pem server-key.pem undo_002
binlog.000002 ca.pem #ib_16384_0.dblwr ibdata1 ibtmp1 mysql.ibd public_key.pem sys
备注:如上图内容所显示则为挂载成功
3.使用mysql
(1)查找mysql具体docker容器
[root@node1 ~]# docker ps | grep mysql
2e0e6049e41b mysql "docker-entrypoint.s…" 12 hours ago Up 12 hours 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
(2)进入容器内部文章来源:https://www.toymoban.com/news/detail-726348.html
[root@node1 ~]# docker exec -it 2e0e6049e41b bash
root@2e0e6049e41b:/#
(3)执行mysql登录和查询命令文章来源地址https://www.toymoban.com/news/detail-726348.html
root@2e0e6049e41b:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.27 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
到了这里,关于Docker----部署mysql的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!