Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently did a clean install of Linux Mint 16 Petra on my laptop.

Before I wiped the old system, I did a backup of all my MySQL databases by going to the Export tab in phpMyAdmin and dumping all the databases into one file. I didn't use any compression.

Now, on the new system, in phpMyAdmin, when I go to the Import tab and try to upload the SQL file, I get this error:

#1046 - No database selected

... Of course no database is selected, I am trying to restore them.

I am not at all an expert in MySQL, I use it to support my web design projects, so I don't understand why this isn't working. It seems to me phpMyAdmin should be able to read from a file that phpMyAdmin created.

How do I restore my databases from the SQL dump file that I created?

share|improve this question
2  
Look into your dumped file and see if there is any create database if not exist mysql ... or similar lines. The dump should contain the data itself. –  val0x00ff Nov 27 '13 at 13:18
add comment

2 Answers 2

It seems that your dump does not have the informations to create the database. Create the database first, then import the dump in that database.

share|improve this answer
    
The database file represents multiple databases. A dozen or so. I'm not sure I remember exactly what their names are. Is there no way to fix this with more of a batch process? –  Dave M G Nov 27 '13 at 13:24
    
If there's no CREATE DATABASE IF NOT EXIST in your dump file, and if the old databases has been removed, then you have to re-create them by hand. –  Vinz Nov 27 '13 at 13:36
add comment
up vote 1 down vote accepted

The solution I used was to search the SQL file for everywhere that this text existed:

-- Database: `my_database_01`

And right under it, add the following lines:

CREATE DATABASE IF NOT EXISTS `my_database_01`;
USE `my_database_01`;

I did this for each database in the SQL dump file, and then I was able to import and restore all databases using phpMyAdmin's import command.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.