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.


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.


  1. Gareth said (8 Jun. 2010):

    Thanks, this error was really bugging me!

  2. willyzl said (28 Oct. 2011):

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

  3. Austin said (1 Nov. 2011):

    you are a godsend, sir.

  4. LJ said (7 Jan. 2012):


    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.



  5. Dennis Guerra said (17 Jan. 2012):

    Thank you so much !!!
    Was desperate :P


  6. Shruti said (12 Feb. 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 said (19 Feb. 2012):

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

  8. Simen said (12 Mar. 2012):

    Thanks… :-)

  9. Kenny said (31 Aug. 2017):

    Thanks. This was literally driving me nuts lol thanks

  10. George said (9 May. 2018):

    This saved my life, thanks!!

  11. Bryan said (22 Jun. 2018):

    This command solve my problem. Thank you.

  12. Tung said (4 Sep. 2018):

    Wow, thanks

  13. Ihsan Caisario said (24 Apr. 2019):

    Thanks, Sir..
    You are Cool

  14. ginhou said (6 May. 2019):

    thanks so much.

    it saved my days from new project

  15. yusuf said (11 May. 2019):

    Thank u man.

  16. paul said (13 Sep. 2019):


Leave a comment