How to import sql file to mysql?

312    Asked by Amitraj in Cyber Security , Asked on Sep 29, 2022

I am trying to import a .sql file using MySQL Workbench and I get this error: ERROR 1046 (3D000) at line 28: No database selected

I have first created an empty database called with the same name as the .sql file but it doesn't work. I have also tried to do it with the mysql command client using:


mysqldump -u root database > file.sql 

But it says there is an error in my SQL syntax. Furthermore, I don't know the path where I have to set the file.sql.

Answered by Andrea Bailey

To import sql file to mysql -


Export:
mysqldump -u username –-password=your_password database_name > file.sql
Import:
mysql -u username –-password=your_password database_name < file>

Your Answer