docker 获取 mysql 5.7 版本的镜像。
将docker 里面的 3306 端口映射出来,否则虚拟机外,可能无法访问,
创建 docker 镜像
docker run -itd -p 3306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=qq123456 mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES UTF8MB4;' --sql-mode="NO_ENGINE_SUBSTITUTION" --innodb-flush-log-at-trx-commit=0 查询数据库当前编码
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
SET NAMES utf8mb4;
SET character_set_client = utf8mb4;
SET character_set_results = utf8mb4;
SET character_set_connection = utf8mb4;
##
SET character_set_server = utf8mb4;
SET character_set_system = utf8mb4;
SET collation_server = utf8mb4_unicode_ci; 修改数据库配置文件
</details>
在[client]段增加下面代码
default-character-set=utf8mb4
在[mysqld]段增加下面的代码
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
Create DATABASE IF NOT EXISTS hexo default charset utf8mb4 COLLATE utf8mb4_general_ci;
创建数据库(访问时,使用外部的用户名,密码)
数据库密码,不能数字开头
docker compose 配置文件
# mysql-db:
mysql_db:
image: mysql:5.7
volumes:
- /_share/master_db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=dbname
ports:
- "3399:3306"
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES UTF8MB4;' --sql-mode="NO_ENGINE_SUBSTITUTION" --innodb-flush-log-at-trx-commit=0
expose:
- "3306"
- "3399"
grant all privileges on *.* to root@'%' identified by 'qq123456' with grant option;
flush privileges;
grant all privileges on . to ‘danielyu’@’%’
with grant option;
create database blog-db;
手机扫一扫
移动阅读更方便
你可能感兴趣的文章