The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
CREATE USER 'reader'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'reader'@'%';
flush privileges;
# docker 中下载 mysql
docker pull mysql
# 查看mysql镜像
docker images mysql
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 8 3218b38490ce 22 months ago 516MB
#启动
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=your_pwd -d mysql
#进入mysql容器
docker exec -it mysql bash
#登录mysql
mysql -uroot -p'root'
#查询用户相关信息
select user, host, authentication_string from user;
#修改 root 密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'youpassord';
exit;
#重新登录
mysql -uroot -p'youpassord'
#进入mysql容器
docker exec -it mysql bash
#登录mysql
mysql -u root -p'youpassord'
#授予root远程登录权限
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
#添加一个新的用户,并授予远程登录的权限
CREATE USER 'tuonioooo'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'tuonioooo'@'%';
flush privileges;