Docker部署MySQL8数据库

1、准备工作

docker pull mysql:8.0.27
Pwd="/data/software/mysql"
mkdir ${Pwd}/{data,logs} -p
chmod 777 ${Pwd}/logs

2、添加配置文件

cat > ${Pwd}/my.cnf << EOF
[mysqld]
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/run/mysqld/mysqld.sock
datadir=/var/lib/mysql
symbolic-links=0
log-error=/var/log/mysql/mysqld.log
slow_query_log_file=/var/log/mysql/slow.log
secure-file-priv= NULL
skip_ssl
default-time-zone='+8:00'
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
log_bin_trust_function_creators=1
event_scheduler=ON
skip_name_resolve
long_query_time=3
slow_query_log=1
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_buffer_pool_size=1024M
key_buffer_size=256M
thread_cache_size=16
wait_timeout=28000
max_connections=1500
open_files_limit=102400
character-set-server=utf8
server_id=1
log-bin=mysqld-bin
default-authentication-plugin=mysql_native_password
explicit_defaults_for_timestamp=1

!includedir /etc/mysql/conf.d/
EOF

3、运行容器

docker run -itd --name mysql \
    -e MYSQL_ROOT_PASSWORD=NTQ34tg*@19VF \
    -v ${Pwd}/my.cnf:/etc/mysql/my.cnf \
    -v ${Pwd}/data:/var/lib/mysql \
    -v ${Pwd}/logs:/var/log/mysql \
    -v /etc/localtime:/etc/localtime \
    -p 3306:3306 \
    --restart=always mysql:8.0.27

4、连接数据库,测试服务是否正常

docker exec -it mysql mysql -uroot -pNTQ34tg*@19VF

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
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> 

也可以使用工具测试是否可以连接
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神奇的海马体

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值