导入sql文件到mysql容器中

导入sql文件到mysql容器中

 1. 在docker-compose文件中增加挂载路径./sqlfile,将sql文件映射进容器。

    volumes:

      - ./data/docker/mysql:/var/lib/mysql

      - ./mysql/:/docker-entrypoint-initdb.d/

      - ./conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf

      - ./sqlfile:/app/sqlfile

  或者可以使用docker cp 的方式。

2. 进入容器内部,导入sql文件到指定数据库。

$ docker exec -it 54e61c8c4846 bash

#mysql -uroot -proot

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| apigateway-ai      |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

5 rows in set (0.00 sec)

mysql> use apigateway-ai;

mysql> source /app/sqlfile/ai_api_profile.sql;

mysql> show tables;

+-------------------------+

| Tables_in_apigateway-ai |

+-------------------------+

| ai_api_profile          |

+-------------------------+

1 row in set (0.00 sec)

结束。

原文地址:https://www.cnblogs.com/liusingbon/p/12842903.html