将SQL转储导入MySQL时出错:未知数据库/无法创建数据库 [英] Error importing SQL dump into MySQL: Unknown database / Can't create database

查看:153
本文介绍了将SQL转储导入MySQL时出错:未知数据库/无法创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑如何导入SQL转储文件.如果不先在MySQL中创建数据库,我似乎无法导入数据库.

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.

这是尚未创建database_name时显示的错误:

This is the error displayed when database_name has not yet been created:

username =有权访问原始服务器上数据库的用户的用户名.
database_name =原始服务器中的数据库名称

username = username of someone with access to the database on the original server.
database_name = name of database from the original server

$ mysql -u username -p -h localhost database_name < dumpfile.sql   
Enter password:  
ERROR 1049 (42000): Unknown database 'database_name' 

如果我以root用户身份登录MySQL并创建数据库,则database_name

If I log into MySQL as root and create the database, database_name

mysql -u root  
create database database_name;  
create user username;# same username as the user from the database I got the dump from.  
grant all privileges on database_name.* to username@"localhost" identified by 'password';  
exit mysql

然后尝试再次导入sql转储:

then attempt to import the sql dump again:

$ mysql -u username -p database_name < dumpfile.sql  
Enter password:  
ERROR 1007 (HY000) at line 21: Can't create database 'database_name'; database exists

我应该如何导入SQL转储文件?

How am I supposed to import the SQL dumpfile?

推荐答案

打开sql文件,并注释掉试图创建现有数据库的行.

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

这篇关于将SQL转储导入MySQL时出错:未知数据库/无法创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆