docker-compose.yml配置
version: '3'
services:
mysql:
image: mysql:latest
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: "123456"
ports:
- 3306:3306
volumes:
- ./datas:/var/lib/mysql:rw
- ./conf/my.cnf:/etc/my.cnf:rw
- ./init:/docker-entrypoint-initdb.d/:ro
command:
--default-authentication-plugin=mysql_native_password #这行代码解决无法访问的问题
my.cnf配置
[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
配置init.sql(服务创建时自动执行)
use mysql;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
网友评论