Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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 a have an error in my SQL syntax. Furthermore, I don't know the path where I have to set the file.sql.

share|improve this question
add comment

migrated from stackoverflow.com Sep 16 '12 at 1:27

This question came from our site for professional and enthusiast programmers.

7 Answers

Export:

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

Import:

mysql -u username –-password=password database_name < file.sql 
share|improve this answer
3  
There has to be no space between -p and password –  tombom Sep 14 '12 at 11:47
    
What if I don't have a password? –  Barbara Dreamer Sep 14 '12 at 11:57
    
Then skip password parameter. –  Kazimieras Aliulis May 31 '13 at 10:35
add comment

You are missing the password in command. Use the following.

mysql --u [username] --password=[password] [database name] < [dump file]
share|improve this answer
2  
There has to be no space between -p and password –  tombom Sep 14 '12 at 11:48
    
Also you want to use mysql, not mysqldump to import –  tombom Sep 14 '12 at 11:49
    
yes tombom, your are right. –  Nitesh Sep 14 '12 at 11:50
add comment

You can also import an .sql file as an already connected user to the database manner :

mysql> use your_database_name;

mysql> source file.sql;
share|improve this answer
add comment
up vote 0 down vote accepted

Damn, juergen d was like 10sec faster with the answer. His answer is of course correct, however considering your error message you can also add to your SQL file at the beginning line like:

USE your_database_name;

This should also do the job and let you import under the Workbench.

EDIT: What path do you mean?

share|improve this answer
    
The path where I have my .sql file, do I have to set it in a specific file? –  Barbara Dreamer Sep 14 '12 at 12:03
    
When you are using mysqldump exported file will be saved in the current folder. It doesn't matter under what path it is. Just when importing from command line you need to be at the same folder or specify path to the file. But this isn't the case when you are using visual tool like Workbench, where you need to select the file from folder tree anyway. Have you tried to add the line I suggested to the SQL file you are trying to import? –  tamashumi Sep 14 '12 at 12:53
add comment

In MySQL Workbench, you can doubleclick the database (on the left panel) to select it as default. Then you should be able to import your dumpfile.

When using commandline, as answered above, mysql -u username –-password=password database_name < file.sql will do the trick. You can also issue mysql -u username –p database_name < file.sql, after which you will be prompted for your password.

share|improve this answer
    
For more similar args, one could also mysql --user=username –-password=password database_name < file.sql –  wkoot Sep 14 '12 at 11:56
    
If you don't have a password, simply omit the -p or --password: mysql --user=username database_name < file.sql –  wkoot Sep 14 '12 at 11:58
    
I´ve selected the database as default schema and it still doesn't work. –  Barbara Dreamer Sep 14 '12 at 12:06
    
The same as before: ERROR 1046 (3D000) at line 28: No database selected. –  Barbara Dreamer Sep 14 '12 at 12:08
    
Yes, it does. But reports the same error. If I do it with the command line and I have the .sql file in C:, how can I indicate that? ... > "C:/file.sql"? –  Barbara Dreamer Sep 14 '12 at 12:12
show 1 more comment

You can try a GUI client like SQLyog.SQLyog allows you to execute a batch file of any size (yes....any size - limited by the OS) created using mysqldump or SQLyog's Export Database As Batch Script option. Select Tools -> Execute SQL Script (Ctrl+Shift+Q). Select the file and press Execute. If SQLyog encounters an error it stops further execution and logs the query as well as the error message in sqlyog.err located in the SQLyog installation folder. You can download the free version from here.

share|improve this answer
add comment

For Windows, in the MySQL server installation directory (e.g. C:\Program Files\MySQL\MySQL Server 5.5), in the my.ini file, add the following line under [mysqld] in the server section:

max_allowed_packet = 16M

And save the changes. (If you are not allowed to save, then copy and paste to desktop and edit again, then paste it in the same location.)

After that, restart your MySQL server.

share|improve this answer
add comment

Your Answer

 
discard

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