docker 安装mysql 8.0.26
sudo docker pull mysql:8.0.26
创建数据目录和配置文件:在你的宿主机上创建一个目录来存放MySQL的配置文件和数据。你还需要为这个目录设置适当的权限1:
sudo mkdir -p /data/mysql8.0/conf /data/mysql8.0/data /data/mysql8.0/logs
sudo chmod -R 755 /data/mysql8.0/conf /data/mysql8.0/data /data/mysql8.0/logs
vim /data/mysql8.0/conf/my.cnf
然后在文件中添加:
[client]
default-character-set = utf8mb4
[mysqld]
datadir=/data/mysql8.0/data
socket=/var/lib/mysql/mysql.sock
log-error=/data/mysql8.0/logs/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
max_allowed_packet = 1G
innodb_log_file_size = 30M
innodb_log_buffer_size = 256M
innodb_file_per_table = 1
innodb_buffer_pool_size=1G
character_set_server = utf8mb4
collation_server = utf8mb4_bin
max_connections=200
lower-case-table-names=1
innodb_strict_mode = 0
secure_file_priv =
transaction-isolation = READ-COMMITTED
default_authentication_plugin=mysql_native_password
default-time-zone = '+08:00'
[mysql]
prompt="\\\\u@\\\\h : \\\\d \\\\r:\\\\m:\\\\s>"
default-character-set=utf8mb4
sudo docker run -itd --name=mysql -v /data/mysql/conf/my.cnf:/data/mysql8.0/conf/my.cnf -v /data/mysql8.0/data:/data/mysql8.0/data -v /data/mysql8.0/logs:/data/mysql8.0/logs -p 3306:3306 -e MYSQL_ROOT_PASSWORD=yourpassword mysql:8.0.26
请将yourpassword替换为你想要设置的MySQL root用户的密码。
本文来自博客园,作者:冰莫莫,转载请注明原文链接:https://www.cnblogs.com/icemomo/p/17872667.html