MySQL 如何将 sql.gz 文件加载到我的数据库?(输入)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2756585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:57:18  来源:igfitidea点击:

How do I load a sql.gz file to my database? (importing)

mysqldatabase

提问by TIMEX

is this right?

这是正确的吗?

mysql -uroot -ppassword mydb < myfile.sql.gz

回答by Artyom

No, it isn't. The right way would be

不,不是。正确的方法是

zcat myfile.sql.gz | mysql -u root -ppassword mydb

Note there can be no space between the -pand passwordif using the -p syntax, refer http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_password

请注意-ppassword如果使用 -p 语法,则和之间不能有空格,请参阅http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_password

回答by Alok Jain

Use the following command:

使用以下命令:

gunzip < databasefile.sql.gz | mysql -u root -p dbname

回答by Renish Gotecha

For Generating dbName.sql.gz

用于生成dbName.sql.gz

mysqldump -u <YOUR USERNAME> -p<YOUR PASSWORD> <YOUR DBNAME> | gzip > ~/mysqlBackup/dbName_`date +%Y%m%d%H%M`.sql.gz

For Loading dbName.sql.gz

用于加载dbName.sql.gz

zcat ~/mysqlBackup/<.SQL.GZ file> | mysql -u <YOUR USERNAME> -p<YOUR PASSWORD> <DATABASE NAME IN WHICH YOU WANT TO LOAD>

回答by kv.

tar -xzf myfile.tar.gz

tar -xzf myfile.tar.gz

Check the extracted sql files using: ls

使用以下命令检查提取的 sql 文件:ls

mysql -u root -p password database < myfile.sql

mysql -u root -p 密码数据库< myfile.sql

回答by Aman Goel

You have to follow below steps:

您必须按照以下步骤操作:

  • First check Mysql service should be running.

  • Then if you have compressed file, decompress it first.

  • Then you will find .sql file after decompressing.
  • Then find import data in left corner in Mysql.
  • Select option import from self-contained file and select your .sql file and specify a new schema name.
  • Then click on import data.
  • After importing you will see your new schema in available schema list.
  • 首先检查Mysql服务是否应该运行。

  • 然后,如果您有压缩文件,请先将其解压缩。

  • 然后你会在解压后找到.sql文件。
  • 然后在Mysql的左下角找到导入数据。
  • 选择选项 import from self-contained file 并选择您的 .sql 文件并指定新的架构名称。
  • 然后点击导入数据。
  • 导入后,您将在可用架构列表中看到新架构。

回答by Shahrukh Anwar

  • You must not use the passworddirectly in the terminal, use without it like follows
  • 你不能password直接在终端中使用,不使用它,如下所示
zcat YOUR_FILE.sql.gz | mysql -u YOUR_DB_USERNAME -p YOUR_DATABASE_NAME
  • Hit enter and when terminal asked for your password, type your password and hope everything will work fine.
  • 按回车键,当终端询问您的密码时,输入您的密码并希望一切正常。