Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore SQL file generated by MySQLDump using command prompt

I have a SQL file generated by MySQLDump. How can I restore it via command prompt?

like image 939
Anuya Avatar asked Jun 11 '10 07:06

Anuya


People also ask

How do I restore a .frm file in MySQL?

1- create some dummy tables with at least one column and SAME NAME with frm files in a new mysql database. 3- copy and paste the old frm files to newly created table's frm files, it should ask you if you want to overwrite or not for each. replace all. 4-start mysql service, and you have your table structure...

How do I restore a .SQL file in MySQL Workbench?

First you will need to download and connect MySQL Workbench to your database. Once connected you will want to click Server > Data Import: On the next screen you will need to click the bubble for "Import from Self-Contained File", then click on the three dots to find the location of the file on your local machine.

Which command is used to restore the database in SQL?

Method 1 – T-SQL The following command is used to restore database called 'TestDB' with backup file name 'TestDB_Full. bak' which is available in 'D:\' location if you are overwriting the existed database.


1 Answers

Run this command (if the mysql executable isn't in your PATH, first go to the directory where the MySQL binary is installed, something like \mysql\bin):

mysql -u username -ppassword databasename < file.sql 

(Note that there is no space between -p and the password)

Or if the file is gzipped (like my backups mostly are) then something like this:

gunzip file.sql.gz | mysql -u username -ppassword databasename 

or on some systems it might be necessary to add the -c flag to gunzip, like so (to force it to output to stdout):

gunzip -c file.sql.gz | mysql -u username -ppassword databasename 
like image 70
Nathan Avatar answered Sep 21 '22 06:09

Nathan