ERROR 1049 (42000): Unknown database 'mydatabasename'

后端 未结 12 1281
故里飘歌
故里飘歌 2020-12-14 07:27

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 restori

相关标签:
12条回答
  • 2020-12-14 07:43

    I had the same issue, i run this command on command line and just like you i had added the ';' at the end. Removing it solved the issue. Instead of this

    mysql -uroot -pmypassword mydatabase<mydatabase.sql;
    

    try this

    mysql -uroot -pmypassword mydatabase<mydatabase.sql
    
    0 讨论(0)
  • 2020-12-14 07:45

    If dump file contains:

    CREATE DATABASE mydatabasename;
    USE mydatabasename; 
    

    You may just use in CLI:

    mysql -uroot –pmypassword < mydatabase.sql
    

    It works.

    0 讨论(0)
  • 2020-12-14 07:50

    Open the sql file and comment out the line that tries to create the existing database and remove USE mydatabasename and try again.

    0 讨论(0)
  • 2020-12-14 07:50

    Create database which gave error as Unknown database, Login to mysql shell:

    sudo mysql -u root -p
    create database db_name;
    

    Now try restoring database using .sql file, -p flag will ask for a sql user's password once command is executed.

    sudo mysql -u root -p db_name < db_name.sql
    
    0 讨论(0)
  • 2020-12-14 07:52

    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;
    0 讨论(0)
  • 2020-12-14 07:53

    I found these lines in one of the .sql files

    "To connect with a manager that does not use port 3306, you must specify the port number:

    $mysqli = new mysqli('127.0.0.0.1','user','password','database','3307');
    

    or, in procedural terms:

    $mysqli = mysqli_connect('127.0.0.0.1','user','password','database','3307');"
    

    It resolved the error for me . So i will suggest must use port number while making connection to server to resolve the error 1049(unknown database).

    0 讨论(0)
提交回复
热议问题