MySQL 错误 1049 (42000):未知数据库“mydatabasename”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19678769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 1049 (42000): Unknown database 'mydatabasename'
提问by La Chi
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".
我正在尝试从 .sql 文件中恢复数据库,我已经在 phpmyadmin 中创建了数据库,并且还在 .sql 文件中使用了 create if not exist 命令,我正在将其恢复到数据库中,并且在 phpmyadmin 和 . sql 文件,即“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,
请帮助我如何解决这个问题。谢谢,
回答by Dobpbiu
If dump file contains:
如果转储文件包含:
CREATE DATABASE mydatabasename;
USE mydatabasename;
You may just use in CLI:
您可以只在 CLI 中使用:
mysql -uroot –pmypassword < mydatabase.sql
It works.
有用。
回答by zessx
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 :
您需要检查mydatabase.sql
并找到这一行:
USE mydatabasename;
Thisname does matter, and it's the one you must use in your command :
这个名称很重要,它是您必须在命令中使用的名称:
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
Two options for you :
两种选择:
- Remove
USE mydatabasename;
in your dump, and keep using :mysql -uroot -pmypassword mydatabase<mydatabase.sql;
- Change your local database name to fit the one in your SQL dump, and use :
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
USE mydatabasename;
在您的转储中删除,并继续使用:mysql -uroot -pmypassword mydatabase<mydatabase.sql;
- 更改本地数据库名称以适合 SQL 转储中的名称,然后使用:
mysql -uroot -pmypassword mydatabasename<mydatabase.sql;
回答by Sathish D
Open the sql file and comment out the line that tries to create the existing database and remove USE mydatabasename
and try again.
打开 sql 文件并注释掉尝试创建现有数据库并删除USE mydatabasename
并重试的行。
回答by molavec
I solved because I have the same problem and I give you some clues:
我解决了,因为我有同样的问题,我给你一些线索:
1.- As @eggyal comments
1.- 作为@eggyal 评论
mydatabase != mydatabasename
So, check your database name
因此,请检查您的数据库名称
2.- if in your file, you want create database, you can't set database that you not create yet:
2.- 如果在你的文件中,你想创建数据库,你不能设置你还没有创建的数据库:
mysql -uroot -pmypassword mydatabase<mydatabase.sql;
change it for:
将其更改为:
mysql -uroot -pmypassword <mydatabase.sql;
回答by Iulian Cucoanis
You can also create a database named 'mydatabasename' and then try restoring it again.
您还可以创建一个名为“mydatabasename”的数据库,然后再次尝试恢复它。
Create a new database using MySQL CLI:
使用 MySQL CLI 创建一个新数据库:
mysql -u[username] -p[password]
CREATE DATABASE mydatabasename;
Then try to restore your database:
然后尝试恢复您的数据库:
mysql -u[username] -p[password] mydatabase<mydatabase.sql;
回答by jhamezzz1315
La Chi's answer works for me.
La Chi的回答对我有用。
You can view his/her answer in the comment of zessx answer in this page. But I initially have a problem with it if you also do just tweak his/her answer like this: mysql -h localhost -u root -p -D mydatabase < mydatabase.sql
.
您可以在此页面的 zessx answer 的评论中查看他/她的答案。但是我最初有它的问题,如果你也别只是捏捏他/她的回答是这样的:mysql -h localhost -u root -p -D mydatabase < mydatabase.sql
。
Also I would suggest that in the mydatabase.sql
portion you include the direct location of it in your computer like "C:\Users\username\desktop"
.
此外,我建议mydatabase.sql
您在该部分中包含它在计算机中的直接位置,例如"C:\Users\username\desktop"
.
Thank you.
谢谢你。
回答by Adil Roubleh
If initially typed the name of the database incorrectly. Then did a Php artisan migrate .You will then receive an error message .Later even if fixed the name of the databese you need to turn off the server and restart server
如果最初键入的数据库名称不正确。然后做了一个 Php artisan migrate。然后你会收到一条错误消息。后来即使修复了数据库的名称,你也需要关闭服务器并重新启动服务器
回答by Sely Lychee
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
回答by Aqsa Zahoor
I found these lines in one of the .sql files
我在 .sql 文件之一中找到了这些行
"To connect with a manager that does not use port 3306
, you must specify the port number:
“要与不使用 port 的管理器连接3306
,您必须指定端口号:
$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).
它为我解决了错误。所以我建议在连接到服务器时必须使用端口号来解决错误1049
(未知数据库)。
回答by Juan Castellon
mysql -uroot -psecret mysql < mydatabase.sql