Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export a mysql database using Command Prompt?

Tags:

mysql

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.

like image 764
Starx Avatar asked Jun 13 '10 07:06

Starx


People also ask

How do I export an entire MySQL database?

Confirm that SQL is selected under format. Click “Go”. Type the file name and select the directory where your exported database is to be saved in the 'Save File' dialogue box on your local computer. Click “Save” and the process of exporting will start.

How do I export a database using Query?

Run the query on a MySQL database. This will generate an output in a grid format. Select the output of the query & click on the export/import option. Now provide a file name along with the format you want to export the data in.

How can I see MySQL database in CMD?

To access a specific database, type the following command at the mysql> prompt, replacing dbname with the name of the database that you want to access: Copy use dbname; Make sure you do not forget the semicolon at the end of the statement. After you access a database, you can run SQL queries, list tables, and so on.


2 Answers

First check if your command line recognizes mysql command. If not go to command & type in:

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 instructions regarding both import and export

like image 148
Starx Avatar answered Sep 23 '22 15:09

Starx


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.

like image 31
Srinivasan.S Avatar answered Sep 22 '22 15:09

Srinivasan.S