docker-compose部署mysql8
切换到mysql目录cd /mnt/mysql创建MySQL数据挂载目录
mkdir data
[*]创建mysql设置挂在目录
mkdir config创建mysql yaml文件
touch mysql.yml编辑yaml文件
vi mysql.yml添加如下内容
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
docker ps进入容器内部
docker exec -it 容器id sh毗连到MySQL
mysql -uroot -p123456修改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
# 添加以下配置
character_set_server = utf8
init_connect='SET NAMES utf8'
default-character-set = utf8
default-character-set = utf8
default-character-set = utf8
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企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]