How do I import an SQL file using the command line in MySQL?

How do I import an SQL file using the command line in MySQL?

 

 

Login to mysql via command line and input the below command

mysql -u username -p database_name < file.sql
on May 12, 2020.

Export:

mysqldump -u username –-password=your_password database_name > file.sql

Import:

mysql -u username –-password=your_password database_name < file.sql
on May 13, 2020.
Add Comment
1 Answer(s)

You can use mysqldump utility to import data. See the details from below link.

shell> mysqldump db_name > backup-file.sql

You can load the dump file back into the server like this:

UNIX

shell> mysql db_name < backup-file.sql

The same in Windows command prompt:

mysql -p -u [user] [database] < backup-file.sql

PowerShell

C:\> cmd.exe /c "mysql -u root -p db_name < backup-file.sql"

MySQL command line

mysql> use db_name;
mysql> source backup-file.sql;
Answered on May 13, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.