1.执行命令如下

  • 映射配置文件
  • 映射数据
  • 设置忽略大小写
docker run -d -p 13306:3306 -v /home/hfg/Soft/mysql/conf:/etc/mysql/conf.d -v \
/home/hfg/Soft/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=r0ot \
--name  mysql mysql:5.7 --lower_case_table_names=1

2. 如下就是启动成功

在这里插入图片描述

3.数据导入

## 查看当前容器
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED        STATUS         PORTS                                                    NAMES
344088daee8a   mysql:5.7   "docker-entrypoint.s…"   15 hours ago   Up 6 minutes   33060/tcp, 0.0.0.0:13306->3306/tcp, :::13306->3306/tcp   mysql
[root@localhost ~]# 
[root@localhost ~]# 
## 进入容器
[root@localhost ~]# docker exec -it 344 bash
root@344088daee8a:/# ls
bin  boot  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@344088daee8a:/# cd /var/lib/mysql
## 将数据拷贝到 /var/lib/mysql,并进行登录
root@344088daee8a:/var/lib/mysql# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.36 MySQL Community Server (GPL)
## 创建数据库
mysql> create dabase xxx;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dabase xxx' at line 1
mysql> create database xxx;
Query OK, 1 row affected (0.00 sec)
mysql> ues xxx;

## 开始进行导入
mysql> source /var/lib/mysql/mysqlxxx_20220207.0924.sql

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐