(1)mysql容器化部署

2023-12-13 05:35:58

mysql容器化部署:

数据持久化(方便数据保存及迁移):

需要持久化两个目录:
创建/mysql

(1)mysql配置文件:
/mysql/mysql-cnf/my.cnf
vim my.cnf
'''
[mysqld]
pid-file ? ? ? ?= /var/run/mysqld/mysqld.pid
socket ? ? ? ? ?= /var/run/mysqld/mysqld.sock
#容器内数据存储路径
datadir ? ? ? ? = /var/lib/mysql
#log-error ? ? ?= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address ? = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections=1000
#sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#mysql57需要设置该参数
#show_compatibility_56=1
#mysql8中需要添加
secure_file_priv=/var/lib/mysql
'''

(2)数据存储目录:
#如果需要迁移将老数据拷贝到该目录下
/mysql/mysql-data
注意:在启动mysql容器前删除两个文件:ib_logfile0和ib_logfile1

(3)启动容器
#此时版本为Mysql8
#拉取镜像
docker pull mysql
#启动容器同时挂载持久化目录
docker run -d -p 13306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /mysql/mysql-data:/var/lib/mysql -v /mysql/mysql-cnf/my.cnf:/etc/mysql/my.cnf --name=mysql --restart=always 3218b38490ce

(4)查看是否启动成功:
docker ps|grep mysql

(5)mysql8无法连接navicat解决方法:
①进入容器内部:
docker exec -it 容器ID /bin/bash
②登录mysql:
mysql -u root -p
③输入密码:
root密码为MYSQL_ROOT_PASSWORD=123456
④mysql用户登录密码加密规则还原成mysql_native_password:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
⑤尝试使用navicat连接mysql

注意:注意给配置文件赋权限

文章来源:https://blog.csdn.net/qq_37651894/article/details/134920514
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。