Docker安装MySql-挂载外部数据和配置

 

http://www.fwhyy.com/2018/05/docker-installs-mysql-to-mount-external-data-and-configuration/

https://www.cnblogs.com/tangxuliang/p/9341271.html

  

docker run -d -p 3306:3306 --restart always --privileged=true --name dockermysql -e MYSQL_ROOT_PASSWORD=123456 -v=/root/dockermysql/config/my.cnf:/etc/my.cnf -v=/root/dockermysql/data:/var/lib/mysql -d mysql

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@VM_0_5_centos dockermysql]# docker run -d -p 3306:3306 --restart always --privileged=true --name dockermysql -e MYSQL_ROOT_PASSWORD=123456 -v=/root/dockermysql/config/my.cnf:/etc/my.cnf -v=/root/dockermysql/data:/var/lib/mysql -d mysql
fd03062b839069d29ffc4500b2c9ff96266893f77f7a778b749ecc6fd8cf11d9
[root@VM_0_5_centos dockermysql]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
fd03062b8390        mysql               "docker-entrypoint.s…"   8 seconds ago       Up 6 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   dockermysql
[root@VM_0_5_centos ~]# docker exec -it dockermysql bash
root@fd03062b8390:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16 MySQL Community Server - GPL
 
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 
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.03 sec)
 
mysql> grant all privileges on *.*  to 'root'@'%' ;
Query OK, 0 rows affected (0.04 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
 
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.02 sec)
 
mysql> exit;
Bye

  

posted on   youhui  阅读(116)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示