MySQL 错误 1049 (42000):未知数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12118627/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:37:23  来源:igfitidea点击:

ERROR 1049 (42000): Unknown database

mysql

提问by aalab002

I can't seem to login to my tutorial database development environment:

我似乎无法登录到我的教程数据库开发环境:

Ayman$ mysql -u blog -p blog_development
Enter password: 
ERROR 1049 (42000): Unknown database 'blog_development'

I can login to the database fine without the blog_development portion:

我可以在没有 blog_development 部分的情况下正常登录数据库:

Ayman$ mysql -u blog -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1858

Not sure what gives as I granted all access:

不确定是什么给了我授予所有访问权限:

mysql> GRANT ALL PRIVILEGES ON blog_development.*
    -> TO 'blog'@'localhost'
    -> IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW GRANTS FOR 'blog'@'localhost'
    -> ;
+----------------------------------------------------------------------------------------- --------------------+
 | Grants for blog@localhost                                                                                        |
 +----------------------------------------------------------------------------------------- --------------------+
| GRANT USAGE ON *.* TO 'blog'@'localhost' IDENTIFIED BY PASSWORD    '*FE4F2D624C07AAEBB979DA5C980D0250C37D8F63' |
| GRANT ALL PRIVILEGES ON `blog`.* TO 'blog'@'localhost'                                                        |
| GRANT ALL PRIVILEGES ON `blog_development`.* TO 'blog'@'localhost'                                           |
+----------------------------------------------------------------------------------------- --------------------+
3 rows in set (0.00 sec)

Anybody have a clue what to try? Thanks! Also, side note- is it weird I have multiple root users?:

有人知道要尝试什么吗?谢谢!另外,旁注 - 我有多个 root 用户是不是很奇怪?:

mysql> select User from mysql.user;
+------+
| User |
+------+
| root |
| root |
|      |
| root |
|      |
| blog |
| root |
+------+
7 rows in set (0.00 sec)

Edit: for those asking- I created the database blog with the CREATE DATABASE command in MySql. Here are my active databases:

编辑:对于那些询问 - 我在 MySql 中使用 CREATE DATABASE 命令创建了数据库博客。这是我的活动数据库:

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+  
| information_schema |
| blog               |
| mysql              |
| performance_schema |
| test               |
+--------------------+ 
5 rows in set (0.00 sec)

采纳答案by Michael Durrant

blog_development doesn't exist

blog_development 不存在

You can see this in sql by the 0 rows affectedmessage

您可以通过0 rows affected消息在 sql 中看到这一点

create it in mysql with

在 mysql 中创建它

mysql> create database blog_development

However as you are using rails you should get used to using

但是,当您使用 rails 时,您应该习惯使用

$ rake db:create

to do the same task. It will use your database.yml file settings, which should include something like:

做同样的任务。它将使用您的 database.yml 文件设置,其中应包括以下内容:

development:
  adapter: mysql2
  database: blog_development
  pool: 5

Also become familiar with:

还要熟悉:

$ rake db:migrate  # Run the database migration
$ rake db:seed     # Run thew seeds file create statements
$ rake db:drop     # Drop the database

回答by RajivRisi

Very simple solution. Just rename your database and configure your new database name in your project.

非常简单的解决方案。只需重命名您的数据库并在您的项目中配置您的新数据库名称。

The problem is the when you import your database, you got any errors and then the database will be corrupted. The log files will have the corrupted database name. You can rename your database easily using phpmyadmin for mysql.

问题是当您导入数据库时​​,您会遇到任何错误,然后数据库将被损坏。日志文件将具有损坏的数据库名称。您可以使用 phpmyadmin for mysql 轻松重命名数据库。

phpmyadmin -> operations -> Rename database to

回答by Praveen Kumar

Its a common error which happens when we try to access a database which doesn't exist. So create the database using

这是当我们尝试访问不存在的数据库时发生的常见错误。所以创建数据库使用

CREATE DATABASE blog_development;

The error commonly occours when we have dropped the database using

当我们使用删除数据库时,通常会发生错误

DROP DATABASE blog_development;

and then try to access the database.

然后尝试访问数据库。