切换到mysql目录
创建MySQL数据挂载目录
创建mysql yaml文件
编辑yaml文件
添加如下内容
- version: '2'
- services: mysql
- container_name: mysql8
- image: mysql:8.0.26
- ports:
- - "3306:3306"
- restart: always
- environment:
- - MYSQL_ROOT_PASSWORD: 123456
- volumes:
- - "/mnt/mysql/data:/var/lib/mysql"
- - "/mnt/mysql/config:/etc/mysql/conf.d"
复制代码 使用docker compose创建并运行mysql容器
- docker-compose -f mysql.yml up -d
复制代码 检察容器id
进入容器内部
毗连到MySQL
修改root账号的密码
- alter user 'root'@'%' identified with mysql_native_password by '123456';
- alter user 'localhost'@'%' identified with mysql_native_password by '123456';
- flush privileges;
复制代码 使用source实行sql文件乱码问题解决方案1
检察数据库编码
- show variables like '%char%';
复制代码 如以下设置不是utf-8,则都设置为utf-8
- set character_set_client=utf8mb4;
- set character_set_connection=utf8mb4;
- set character_set_database=utf8mb4;
- set character_set_results=utf8mb4;
- set character_set_server=utf8mb4;
复制代码 使用source实行sql文件乱码问题解决方案2
- docker ps -- 查看容器
- docker exec -it 容器id sh -- 进入容器内部
- docker cp 容器id:/etc/mysql/my.cnf /mnt/mysql/config -- 复制容器内部的配置文件
- vi /mnt/mysql/config/my.cnf
- # 添加以下配置
- [mysqld]
- character_set_server = utf8
- init_connect='SET NAMES utf8'
- [mysql]
- default-character-set = utf8
- [mysql.server]
- default-character-set = utf8
- [mysqld_safe]
- default-character-set = utf8
- [client]
- default-character-set = utf8
复制代码 数据库毗连工具无法毗连问题
- use mysql;
- update user set host = '%' where user = 'root';
- flush privileges;
- ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
- FLUSH PRIVILEGES;
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |