Docker安装MySQL

Arthit 于 2023-12-07 发布

Docker 安装 MySQL

创建配置文件

cd /root/mysql/conf
touch config-file.cnf

复制以下代码到 config-file.cnf 文件

[client]
default_character_set=utf8mb4
[mysqld]
collation_server=utf8mb4_general_ci
character_set_server=utf8mb4
lower_case_table_names=1
log-error=/var/log/mysql/error.log
log-bin=/var/log/mysql/

docer-compose 文件

version: '3'

services:
    mysql:
        container_name: mysql
        privileged: true
        volumes:
            - '/root/mysql/log:/var/log/mysql'
            - '/root/mysql/data:/var/lib/mysql'
            - '/root/mysql/conf:/etc/mysql/conf.d'
        environment:
            - TZ=Asia/Shanghai
            - MYSQL_ROOT_PASSWORD=password
        ports:
            - '9306:3306'
        image: 'mysql:latest'

补充

修改密码的加密方式

8.0 版本及以上密码的加密方式变了,有些客户端暂时不支持,导致连接时可能报错。

ALTER USER 'root'@'%' IDENTIFIED WITH 'mysql_native_password' BY 'password';
FLUSH PRIVILEGES; #刷新权限配置

# SELECT user, host, plugin FROM mysql.user WHERE user = 'root';