查看官方文档
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
-
- 启动5.7(未测试,我想装8)
[root@swl123 ~]# docker run -d -p 3310:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mysql3310 mysql:5.7
- 启动8.0.26
-
- 学会使用–help,这里使用8.0.26版本,显示的属性都是可以在命令行后进行添加
- -
MySQL8一般要设置区分表名大小写以及密码策略
- -
通过help命令知道区分表大小写lower_case_table_names可以在启动时添加
docker run -it --rm mysql:8.0.26 --verbose --help
-
- 整理启动命令,添加–lower_case_table_names=1,–skip_name_resolve=no:关闭dns解析,这样外网访问数据库会快点
[root@swl123 ~]# docker run -p 3388:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d --name mysql8 mysql:8.0.26 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1 --skip_name_resolve=no
- 3.有惊无险的启动了, 进入容器
[root@swl123 ~]# docker run -p 3388:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d --name mysql8 mysql:8.0.26 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --lower_case_table_names=1
612eaf5c2777b8ce3d54f0073d437d3e0d4a3ecba0ca57c7c49a6cc71f5b7054
[root@swl123 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
612eaf5c2777 mysql:8.0.26 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 33060/tcp, 0.0.0.0:3388->3306/tcp, :::3388->3306/tcp mysql8
c6a750b3039f portainer/portainer "/portainer" 4 hours ago Up 4 hours 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp portainer
34fb3c029026 elasticsearch:7.13.3 "/bin/tini -- /usr/l…" 5 hours ago Up 5 hours 0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp elasticsearch02
[root@swl123 ~]# docker exec -it 612eaf5c2777 /bin/bash
root@612eaf5c2777:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9
Server version: 8.0.26 MySQL Community Server - GPLCopyright (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> use
ERROR:
USE must be followed by a database name
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql>
不能远程访问请设置服务器的防火墙,Linux的防火墙
/开启6379端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
//检查端口是否开启
firewall-cmd --query-port=6379/tcp
//重启防火墙
firewall-cmd --reload
- 很奇怪,不用再设置密码策略,远程也可以连接,那就测试表名大小写问题:
- 没问题就可以愉快的用数据库了
- 此博客是边写边安装,确实没有遇到想象中的一些问题,很奇怪