Administrator
Published on 2025-01-19 / 20 Visits
1
0

docker安装mysql8

一、mysql配置文件准备

创建文件文件夹
/data/mysql8/conf
/data/mysql8/data
/data/mysql8/log
/data/mysql8/mysql-files

my.cnf文件
vi /data/mysql8/conf/my.cnf

[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

init_connect='SET collation_connection = utf8_unicode_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_unicode_ci

default-time-zone='+08:00'

skip-character-set-client-handshake

skip-name-resolve

log-bin=/var/lib/mysql/mysql-bin

binlog-format=ROW

server-id=1

expire_logs_days = 30

二、docker启动脚本


MYSQL_DEFAULT_AUTH:默认的认证插件,caching_sha2_password比mysql_native_password更安全,高版本默认采用。

三、docker交互式进入mysql

docker exec -it 066c080e3798 mysql -u root -p123456 my_database

四、mysql添加用户

CREATE USER 'admin'@'%' IDENTIFIED BY '123456';

alter user admin identified with mysql_native_password by '123456';

GRANT ALL PRIVILEGES ON . TO 'admin'@'%';

FLUSH PRIVILEGES;



Comment