Docker 部署mysql8 & Navicat 连接配置

docker 部署mysql 8

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

# 定义容器名称
container_name="mysql8"

# 检查容器是否在运行
if sudo docker ps -q -f name=$container_name >/dev/null; then
    echo "Stopping and removing the container..."
    # 停止并删除容器
    sudo docker stop $container_name && sudo docker rm $container_name
    echo "Container stopped and removed."
fi

# 重新启动新的mysql
sudo docker run --restart=always -p 3306:3306 --name $container_name \
-v $PWD/mysql8/conf:/etc/mysql/conf.d \
-v $PWD/mysql8/logs:/var/log/mysql \
-v $PWD/mysql8/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-e TZ=Asia/Shanghai \
-d mysql
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
-- 登录
mysql -uroot -p

-- 查看
select user, host, plugin from user;

-- 修改
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;

-- 查看
select user, host, plugin from user;