在 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/