Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR 1049 (42000): Unknown database 'mydatabasename'

Tags:

mysql

I am trying to restore database from .sql file , i have created the database in phpmyadmin and also using the create if not exist command in the .sql file which i am restoring to the database and both names of database are same in phpmyadmin and .sql file which is"mydatabase".

Here is the command which i am using to restore database.

mysql -uroot -pmypassword mydatabase<mydatabase.sql; 

When i execute the above command i am getting the following error, i have also given all the permission to the user upon this database.

ERROR 1049 (42000): Unknown database 'mydatabasename' 

Please help me how can i solve this issue. Thanks,

like image 351
La Chi Avatar asked Oct 30 '13 09:10

La Chi


People also ask

How do I fix an unknown database error?

This type of error occurs if you select any database that does not exist in MySQL. Let us first display the error of unknown database in JDBC. To remove this type of error, just go to MySQL command line and show all database names and use the chosen one from there i.e. the database which really exist.


2 Answers

If dump file contains:

CREATE DATABASE mydatabasename; USE mydatabasename;  

You may just use in CLI:

mysql -uroot –pmypassword < mydatabase.sql 

It works.

like image 131
Dobpbiu Avatar answered Sep 20 '22 00:09

Dobpbiu


Whatever the name of your dump file, it's the content which does matter.

You need to check your mydatabase.sql and find this line :

USE mydatabasename; 

This name does matter, and it's the one you must use in your command :

mysql -uroot -pmypassword mydatabasename<mydatabase.sql; 

Two options for you :

  1. Remove USE mydatabasename; in your dump, and keep using :
    mysql -uroot -pmypassword mydatabase<mydatabase.sql;
  2. Change your local database name to fit the one in your SQL dump, and use :
    mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
like image 21
zessx Avatar answered Sep 19 '22 00:09

zessx