Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to restore mysql database from a .sql file [duplicate]

Tags:

sql

mysql

I have a testDBbackup.sql file. I dropped the mysql database a while back and I was wondering how I could restore it from my backup file. I am using a Mac. I was hoping somebody could show me how to do it from the command line, unless there is an easier way from the file system or something.


1 Answers

If your file contains the database create code and that is not conflicting with existing databases. Just go with.

mysql -u root -p
-- You'll be prompted for password
mysql> source filename.sql

If database with a given name already exists and you only want to dump data into it via terminal.

mysql -u root -p testdb < filename.sql
-- You'll be prompted for password

If you have to create it and then dump

mysql -u root -p
-- You'll be prompted for password
mysql> create database test;
mysql> source filename.sql

Make sure you replace root with your actual user, testdb with your database name and filename with actual file.

like image 50
Dark Knight Avatar answered Feb 05 '26 21:02

Dark Knight