docker安装mysql

1、拉取mysql镜像

docker pull mysql:8.0

2、配置mysql

mkdir -p /date/mysql/conf
mkdir -p /date/mysql/data
mkdir -p /date/mysql/logs
#配置my.cnf

[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
# 设置东八区时区
default-time_zone = '+8:00'
# 设置密码验证规则,default_authentication_plugin参数已被废弃
# 改为authentication_policy
#default_authentication_plugin=mysql_native_password
authentication_policy=mysql_native_password

#secure_file_priv=/var/lib/mysql
secure_file_priv=
init_connect='SET collation_connection = utf8mb4_0900_ai_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
skip-character-set-client-handshake
skip-name-resolve

3、启动mysql,启动需要注意挂载文件夹权限,已经挂载文件位置

docker run -d -p 3306:3306 --name mysql --restart=always --privileged=true \
-v /data/mysql/logs:/var/log/mysql \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/conf:/etc/mysql/conf.d \
-e TZ=Asia/Shanghai \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:8.0

4、配置mysql远程登录用户

#进入容器,base可以换成/bin/bash
docker exec -it mysql bash
#登录mysql,密码自行替换
mysql -u root -p123456
#选择数据库
use mysql;
#修改认证方式
ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER root@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
--刷新权限
FLUSH PRIVILEGES;

 

posted @ 2024-08-01 16:33  Sdy8571  阅读(51)  评论(0编辑  收藏  举报