mysql - 如何在 ubuntu 操作系统上启动 mysql 服务时导入 .sql 文件

标签 mysql linux docker ubuntu

在 ubuntu 上安装 mysql 后,我想使用以下命令启动 mysql 服务,该命令将启动服务并创建架构和表。

service mysql start && mysql -u root -e "CREATE DATABASE organzation; use organzation; CREATE TABLE employee(Email varchar(30) NOT NULL)"  

现在假设我有一个file.sql文件,如何在启动mysql服务时导入这个file.sql。
PS: mysql -u username -p database_name < file.sql 这在启动 mysql 服务时不起作用。

最佳答案

来自mysql Docker :

Initializing a fresh instance

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.

您只需将 .sql 文件放入 /docker-entrypoint-initdb.d 目录即可。

关于mysql - 如何在 ubuntu 操作系统上启动 mysql 服务时导入 .sql 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759842/

相关文章:

php - 如何基于表格添加自定义列 - Laravel

java - 如何使用 Groovy 或 Java 捕获 telnet 提示符?

json - 在 linux 中使用 jq 解析 JSON 文件

docker - Docker 命令中的 --net=host 选项到底有什么作用?

docker - 来自守护程序 : manifest for ibmblockchain/fabric-peer:latest not found 的错误响应

python - tensorflow上的“Illegal instruction (core dumped)”> 1.6

php - 如何提高网站标题搜索结果

mysql - hibernate + MySQL : How to set the encoding utf-8 for database and tables

mysql - 文件 mysqld.sock 被删除并不断重新创建

linux - 如何在 Ubuntu WSL 上安装和运行 Tacotron2?