ERROR 1049 (42000): Base de datos desconocida

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:

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?:

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:

| Database           |
| information_schema |
| blog               |
| mysql              |
| performance_schema |
| test               |
5 rows in set (0.00 sec)

preguntado el 25 de agosto de 12 a las 03:08

did you actually create the database? mysql -u blog -p logs into mysql but does not select the database. -

yup, there it is in mySQL - blog, and you were trying blog_development in rails (which is the better name to use and the one suggested by the sample database.yml or development). -

3 Respuestas

blog_development doesn't exist

You can see this in sql by the 0 rows affected mensaje

create it in mysql with

mysql> create database blog_development

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

$ rake db:create

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

  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

Respondido 25 ago 12, 03:08

I created the database blog using the mysql> CREATE DATABASE command. In the past this has created a development environment for me? Unless I am mistaken? - aalab002

Yes, that will work but there is the possibility of the sql command and the rails database.yml not matching. I came from a SQL background before rails and I initially did the SQL commands route but as you learn rails you'll find using rails commands to create the db is the way to go. - Michael Durant

In case you're a noob like me, don't forget to terminate your commands with ; Otherwise you'll just see the --> symbol on the next line - chase denecke

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 -> operations -> Rename database to

respondido 25 nov., 13:11

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.

Respondido 11 ago 13, 14:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.