Error importing SQL dump into MySQL: Unknown database / Can't create database

前端 未结 5 915
别跟我提以往
别跟我提以往 2020-12-12 16:13

I\'m confused how to import a SQL dump file. I can\'t seem to import the database without creating the database first in MySQL.

This is the error displayed when

相关标签:
5条回答
  • 2020-12-12 16:17

    I create the database myself using the command line. Then try to import again, it works.

    0 讨论(0)
  • 2020-12-12 16:18

    Open the sql file and comment out the line that tries to create the existing database.

    0 讨论(0)
  • 2020-12-12 16:32

    This is a known bug at MySQL.

    bug 42996
    bug 40477

    As you can see this has been a known issue since 2008 and they have not fixed it yet!!!

    WORK AROUND
    You first need to create the database to import. It doesn't need any tables. Then you can import your database.

    1. first start your MySQL command line (apply username and password if you need to)
      C:\>mysql -u user -p

    2. Create your database and exit

      mysql> DROP DATABASE database;  
      mysql> CREATE DATABASE database;  
      mysql> Exit  
      
    3. Import your selected database from the dump file
      C:\>mysql -u user -p -h localhost -D database -o < dumpfile.sql

    You can replace localhost with an IP or domain for any MySQL server you want to import to. The reason for the DROP command in the mysql prompt is to be sure we start with an empty and clean database.

    0 讨论(0)
  • 2020-12-12 16:35

    If you create your database in direct admin or cpanel, you must edit your sql with notepad or notepad++ and change CREATE DATABASE command to CREATE DATABASE IF NOT EXISTS in line22

    0 讨论(0)
  • 2020-12-12 16:44

    It sounds like your database dump includes the information for creating the database. So don't give the MySQL command line a database name. It will create the new database and switch to it to do the import.

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