Fixing the « #1046: No database selected » error

Here is the simple, quick fix to the « #1046: No database selected » error when importing a .sql file from a Wamp installation in phpMyAdmin.

Fix:

In phpMyAdmin, click the Export tab situated under Home instead of the one when you are viewing the database to export. This will allow you to export entire databases and not only the tables contained in it. This might not work for users of hosting sites such as Hostmonster or Hostgator, since they pick the database names for you.

Alternative fix:

  1. Create the database on your server and note down the name.
  2. Open your .sql file with a text editor. You might want to use something other than Notepad since it doesn’t recognize the line breaks.
  3. Insert the following line before your first CREATE TABLE command in your .sql file:
    USE yourdatabasename;

    Be careful to write in the right database name. Hostmonster users, for example, will have their username in front of their database name. Therefore, the products database is in fact named username_products.

  4. Save your .sql file and import it using the import tab in phpMyAdmin.

Source

  1. Gareth a dit (8 juin. 2010):

    Thanks, this error was really bugging me!

  2. willyzl a dit (28 oct. 2011):

    Very Good solution. It is what I try looking for days. Thank you for your cool solutions. :DD

  3. Austin a dit (1 nov. 2011):

    you are a godsend, sir.

  4. LJ a dit (7 jan. 2012):

    Hi,

    I still cant do it. After i followed the steps I get and erro 1044. Could you post a video on how to do it? That would be really helpful.
    My whole website is ready and this is the final step and I am stuck here. I am not a web developer infact and not sure how to resolve it.

    Cheers,

    LJ

  5. Dennis Guerra a dit (17 jan. 2012):

    Thank you so much !!!
    Was desperate :P

    Dennis

  6. Shruti a dit (12 fév. 2012):

    Wow! Works like a charm!
    I got 1050 error after that.. So deleted the existing tables in that database..
    Thanks a lot!

  7. Grazzer a dit (19 fév. 2012):

    Was struggling to do this. Used your instructions. All done and dusted. Many thanks …

  8. Simen a dit (12 mar. 2012):

    Thanks… :-)

Laisser un commentaire