如何使用命令提示符导出 mysql 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3031412/
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
How to export a mysql database using Command Prompt?
提问by Starx
I have a database that is quite large so I want to export it using Command Prompt but I don't know how to.
我有一个非常大的数据库,所以我想使用命令提示符导出它,但我不知道如何。
I am using WAMP.
我正在使用 WAMP。
回答by Starx
First check if your command line recognizes mysql command. If not go to command & type in:
首先检查您的命令行是否识别 mysql 命令。如果没有转到命令并输入:
set path=c:\wamp\bin\mysql\mysql5.1.36\bin
Then use this command to export your database:
然后使用此命令导出您的数据库:
mysqldump -u YourUser -p YourDatabaseName > wantedsqlfile.sql
You will then be prompted for the database password.
然后将提示您输入数据库密码。
This exports the database to the path you are currently in, while executing this command
这会将数据库导出到您当前所在的路径,同时执行此命令
Note: Here are some detailed instructionsregarding both import and export
回答by Srinivasan.S
Simply use the following command,
只需使用以下命令,
For Export:
出口:
mysqldump -u [user] -p [db_name] | gzip > [filename_to_compress.sql.gz]
For Import:
对于进口:
gunzip < [compressed_filename.sql.gz] | mysql -u [user] -p[password] [databasename]
Note:There is no space between the keyword '-p' and your password.
注意:关键字“-p”和您的密码之间没有空格。
回答by Mitesh vaghela
First of all open command prompt then open bindirectory in cmd(i hope you're aware with cmdcommands) go to bindirectory of your MySql folder in WAMPprogram files.
首先打开命令提示符,然后在cmd 中打开bin目录(我希望你知道cmd命令)转到WAMP程序文件中MySql 文件夹的bin目录。
run command
运行命令
mysqldump -u db_username -p database_name > path_where_to_save_sql_file
press enter system will export particular database and create sql file to the given location.
按 Enter 系统将导出特定数据库并在给定位置创建 sql 文件。
i hope you got it :) if you have any question please let me know.
我希望你明白了:) 如果你有任何问题,请告诉我。
回答by Umesh Patil
Well you can use below command,
那么你可以使用下面的命令,
mysqldump --databases --user=root --password your_db_name > export_into_db.sql
mysqldump --databases --user=root --password your_db_name > export_into_db.sql
and the generated file will be available in the same directory where you had ran this command.
生成的文件将在您运行此命令的同一目录中可用。
You could find more on the official reference for mysqldump
: Import Export MySQL DB
您可以在以下官方参考资料中找到更多信息mysqldump
:Import Export MySQL DB
Note: use --databases
instead of --database
since the last one is no more supported.
注意:使用--databases
而不是--database
因为不再支持最后一个。
Enjoy :)
享受 :)
回答by user2484830
Go to command prompt at this path,
转到此路径的命令提示符,
C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>
C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin>
Then give this command to export your database (no space after -p)
然后给出这个命令来导出你的数据库(-p 后没有空格)
mysqldump -u[username] -p[userpassword] yourdatabase > [filepath]wantedsqlfile.sql
mysqldump -u[username] -p[userpassword] yourdatabase > [filepath]wantedsqlfile.sql
回答by Opentuned
Locate your mysql instance with:
使用以下命令找到您的 mysql 实例:
which mysql
If this is correct then export with the following (else navigate to the mysql instance in your mamp folder in bin):
如果这是正确的,则使用以下内容导出(否则导航到 bin 中 mamp 文件夹中的 mysql 实例):
mysqldump -u [username] -p [password] [dbname] > filename.sql
And if you wish to zip it at the sametime:
如果您想同时压缩它:
mysqldump -u [username] -p [password] [db] | gzip > filename.sql.gz
You can then move this file between servers with:
然后,您可以使用以下命令在服务器之间移动此文件:
scp [email protected]:/path_to_your_dump/filename.sql.gz your_detination_path/
(where xxx.xxx.xxx.xxx is the server IP address)
(其中xxx.xxx.xxx.xxx为服务器IP地址)
And then import it with:
然后使用以下命令导入它:
gunzip filename.sql.gz | mysql -u [user] -p [password] [database]
回答by arcadius
To export PROCEDUREs, FUNCTIONs & TRIGGERs too, add --routines
parameter:
要导出 PROCEDURE、FUNCTION 和 TRIGGER,请添加--routines
参数:
mysqldump -u YourUser -p YourDatabaseName --routines > wantedsqlfile.sql
mysqldump -u YourUser -p YourDatabaseName --routines > wantedsqlfile.sql
回答by Ossama
Give this command to export your database, this will include date as well
给出这个命令来导出你的数据库,这也将包括日期
mysqldump -u[username] -p[userpassword] --databases yourdatabase | gzip > /home/pi/database_backup/database_`date '+%m-%d-%Y'`.sql.gz
(no space after -p)
(-p 后没有空格)
回答by Sachin
I have installed my wamp server in D: drive so u have to go to the following path from ur command line->(and if u have installed ur wamp in c: drive then just replace the d: wtih c: here)
我已经在 D: 驱动器中安装了我的 wamp 服务器,所以你必须从你的命令行转到以下路径->(如果你已经在 c: 驱动器中安装了你的 wamp,那么只需在这里替换 d: wtih c:)
D:\>cd wamp
D:\wamp>cd bin
D:\wamp\bin>cd mysql
D:\wamp\bin\mysql>cd mysql5.5.8 (whatever ur verserion will be displayed here use keyboard Tab button and select the currently working mysql version on your server if you have more than one mysql versions)
D:\wamp\bin\mysql\mysql5.5.8>cd bin
D:\wamp\bin\mysql\mysql5.5.8\bin>mysqldump -u root -p password db_name > "d:\backupfile.sql"
here rootis user of my phpmyadmin passwordis the password for phpmyadmin so if u haven't set any password for root just nothing type at that place,db_name is the database (for which database u r taking the backup) ,backupfile.sql is the file in which u want ur backup of ur database and u can also change the backup file location(d:\backupfile.sql) from to any other place on your computer
这里root是我的 phpmyadmin 的用户密码是phpmyadmin 的 密码所以如果你没有为 root 设置任何密码只是在那个地方什么都不输入,db_name 是数据库(你备份哪个数据库),backupfile.sql 是您想要备份您的数据库的文件,您还可以将备份文件位置(d:\backupfile.sql)从计算机上的任何其他位置更改为
回答by Nanhe Kumar
mysqldump -h [host] -p -u [user] [database name] > filename.sql
Example in localhost
本地主机中的示例
mysqldump -h localhost -p -u root cookbook > cookbook.sql