docker安装mysql

使用docker安装mysql网上有很多教程,这里只是记录本人设置的操作,不想重复查网上教程对mysql配置文件做其他配置而已

mkdir -p /opt/mysql/{data,conf,logs}
vi /opt/conf/my.cnf
#复制下面的内容放到my.cnf文件中
[mysql]
#客户端使用的字符集默认为utf8mb4
default-character-set=utf8mb4

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
character-set-server=utf8mb4
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#忽略表名不区分大小写
lower_case_table_names=1
#支持不在分组里的字段也能查询
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock
docker run -d --privileged=true --name mysql \
--restart=always \
-p 10036:3306 \
-e MYSQL_ROOT_PASSWORD=1234 \
-v /opt/mysql/data:/var/lib/mysql \
-v /opt/mysql/conf/my.cnf:/etc/my.cnf \
-v /opt/mysql/logs:/var/log/mysql \
mysql:5.7
#设置远程登录访问
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '设置远程登录密码' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;

你可能感兴趣的:(docker,mysql,docker,数据库)