docker安装mysql并持久化
参考博客:https://blog.csdn.net/weixin_38657051/article/details/98596926
1. 拉取镜像:
docker pull mysql:latest
2. 创建持久化文件夹
## 创建mysql的数据持久化配置文件夹 sudo mkdir -p /home/qtdev/bi/mysql/conf ## 创建mysql的数据持久化数据文件夹 sudo mkdir -p /nfs/mysql/data ## 创建mysql的日志文件夹 sudo mkdir -p /home/qtdev/bi/mysql/logs
3. 配置mysql文件
cd /home/qtdev/bi/mysql/conf
vim my.cnf
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql secure-file-priv= NULL lower_case_table_names=1 sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION # Custom config should go here !includedir /etc/mysql/conf.d/
4. 使用docker run语句启动mysql服务
sudo docker run -itd -p 3306:3306 --name onedata-mysql -v /home/qtdev/bi/mysql/conf:/etc/mysql/conf -v /nfs/mysql/data:/var/lib/mysql -v /home/qtdev/bi/mysql/logs:/logs -e MYSQL_ROOT_PASSWORD=Onedata#@123 mysql
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
## 启动参数说明 #
# 提升root权限 --privileged=true #
# 将容器的 3306 端口映射到主机的 3306 端口。 -p 3306:3306 #
# 将宿主机上的当前目录下的conf目录挂载到容器的/etc/mysql/conf目录 -v $PWD/conf:/etc/mysql/conf #
# 将宿主机上的当前目录下的data目录挂载到容器的 /var/lib/mysql -v $PWD/data:/var/lib/mysql #
# 将宿主机上的当前目录下的 logs 目录挂载到容器的 /logs。 -v $PWD/logs:/logs
5 .验证
sudo docker ps -a
sudo docker logs -f d970a6eedff1
sudo docker exec -it d970a6eedff1 /bin/bash
sudo docker rm d970a6eedff1
docker logs -f e2c845247f07
mysql -h 127.0.0.1 -u root -p
6. Q&A
Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
修改账户密码加密规则并更新用户密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新一下用户的密码
FLUSH PRIVILEGES; #刷新权限
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
select @@sql_mode
SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';