ERROR 1049 (42000): Unknown database - mysql

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:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)

blog_development doesn't exist
You can see this in sql by the 0 rows affected message
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:
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

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

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.

Related

[HY000][1130] null, message from server: "Unknown error 1130"

Hi if I use mysql itself I can see my tables and databases and I checked the port on the MySQL variables and it was the same as 3306.
I am not sure what's wrong. I also granted privileges to localhost for the user.
Here is a screenshot of what it shows me:
I think I just updated my PhpStorm and now it is not working any more.
mysql> SELECT
-> user
-> FROM
-> mysql.user;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 49
Current database: *** NONE ***
+---------------+
| user |
+---------------+
| imdi_mg2 |
| mysql.session |
| mysql.sys |
| root |
+---------------+
4 rows in set (0.11 sec)
I am not sure why mysql goes away and comes back in the middle
not sure how but grant should be on % not on localhost this was really annoying:
create user 'user'#'%' identified by 'pass'
GRANT ALL PRIVILEGES ON imdi_mg2.* TO 'user'#'%' WITH GRANT OPTION;
there will be people having this issue hopefully helps someone!

while creating and deleting user in mysql ERROR 1396 (HY000): Operation CREATE USER

I am trying to create new user in mysql,
create user 'saravanakumar'#'localhost' identified by 'saravanakumar';
it shows error as,
ERROR 1396 (HY000): Operation CREATE USER failed for 'saravanakumar'#'localhost'
after I read this
ERROR 1396 (HY000): Operation CREATE USER failed for 'jack'#'localhost'
I delete user.But I can't.It shows
mysql> SELECT User FROM mysql.user;
+---------------+
| User |
+---------------+
| root |
| saravanakumar |
| saravanakumar |
| |
| root |
| saravanakumar |
| |
| root |
+---------------+
8 rows in set (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT User FROM mysql.user;
+---------------+
| User |
+---------------+
| root |
| saravanakumar |
| saravanakumar |
| |
| root |
| saravanakumar |
| |
| root |
+---------------+
8 rows in set (0.00 sec)
how can i delete all these user in table and how can i create a single user.What is the root cause of this problem? experts please help me.
ERROR 1396 (HY000): Operation CREATE USER failed for 'saravanakumar'#'localhost'
Does indeed indicate that the user already exists or did exist.
FLUSH PRIVILEGES doesn't delete users.
Reloads the privileges from the grant tables in the mysql database.
The server caches information in memory as a result of GRANT, CREATE USER,
CREATE SERVER, and INSTALL PLUGIN statements. This memory is not released
by the corresponding REVOKE, DROP USER, DROP SERVER, and UNINSTALL PLUGIN
statements, so for a server that executes many instances of the statements
that cause caching, there will be an increase in memory use.
This cached memory can be freed with FLUSH PRIVILEGES.
You are looking for DROP USER.
DROP USER user [, user] ...
http://dev.mysql.com/doc/refman/5.1/en/drop-user.html
Order of buisness would be:
DROP USER 'saravanakumar'#HOSTNAME;
CREATE USER 'saravanakumar'#HOSTNAME [IDENTIFIED BY 'password'];
You will probably need to flush privileges if you use delete from (do not).
Remember: this does not necessarily revoke all the privileges this user may have (like table privileges), you will have to do this yourself - if you don't you may not be able to recreate the user.
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'saravanakumar'#HOSTNAME;
DELETE FROM mysql.user WHERE user='saravanakumar';
FLUSH PRIVILEGES;
CREATE USER 'saravanakumar'#HOSTNAME [IDENTIFIED BY 'password'];
"user" requires you to specify an account name
Syntax for account names is 'user_name'#'host_name'
and
An account name consisting only of a user name is equivalent
to 'user_name'#'%'. For example, 'me' is equivalent to 'me'#'%'.
Additional reading: http://dev.mysql.com/doc/refman/5.1/en/account-names.html
Please read those bug reports for further clarification
http://bugs.mysql.com/bug.php?id=28331
http://bugs.mysql.com/bug.php?id=62255
To me works, I set hostname in UPPERCASE:
DROP USER 'user'#'LOCALHOST'
select User, Host from mysql.user;
Made it clear for me what was happening. I had ended up with the same user under several hosts. Deleting unwanted ones helped!

Issue inserting data into a mysql table using cloudfoundry's vmc utility

I am having issues with user privileges in mysql and cloudfoundry.
I was able to insert data into a table and I am trying to insert data into another table and running into the following issue:
mysql> source /home/julien/Documents/donnees/projets/Site-Rencontres/java/src/main/resources/misc/sql/geolocation.sql
ERROR 1142 (42000): INSERT command denied to user 'uEs8kO1Aqdhlr'#'172.30.49.208' for table 'geolocation'
Can anyone please clarify to me how user privileges work on mysql for cloudfoundry?
EDIT 1: Some info:
+-------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for uEs8kO1Aqdhlr#% |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'uEs8kO1Aqdhlr'#'%' IDENTIFIED BY PASSWORD '*A826C24476F83F907DC66060E4C2705D92E151ED' WITH MAX_USER_CONNECTIONS 20 |
| GRANT ALL PRIVILEGES ON `de2474fdd53114ebfbb17b3c236676a28`.* TO 'uEs8kO1Aqdhlr'#'%' |
+-------------------------------------------------------------------------------------------------------------------------------------------+
EDIT 2: Some more info:
mysql> select user();
+-----------------------------+
| user() |
+-----------------------------+
| uEs8kO1Aqdhlr#172.30.49.208 |
+-----------------------------+
1 row in set (0.80 sec)
mysql> select current_user();
+-----------------+
| current_user() |
+-----------------+
| uEs8kO1Aqdhlr#% |
+-----------------+
1 row in set (0.85 sec)
EDIT 3: Yet some more info:
I realized that my sql script was referring the wrong schema (here called dummy):
insert into dummy.geolocation
Removing the "dummy." allowed me to run the script without any error. Why this gave me the above error I am not sure. If any one can explain, that would be useful...
CF provisions both the mysql instance as well as a database. Therefore when you bind a mysql service you actually bind the database to your app. If you notice when vmc tunnelling to the mysql service, it gives you the username/password as well as a key called "name", that is the schema name the tunnel is on. Operations against other schemas would be considered out of the CF account used.

MySQL: grant permissions denied for CREATE

I setup a database & user along with grant permissions how I normally do and I'm still getting access denied and I'm not sure why:
[root#server23 redditonrails]# mysql -u redditonrails -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 431954
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use redditonrails_development;
Database changed
mysql> create table test;
ERROR 1142 (42000): CREATE command denied to user 'redditonrails'#'localhost' for table 'test'
mysql> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for redditonrails#localhost |
+------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'redditonrails'#'localhost' IDENTIFIED BY PASSWORD '*******' |
| GRANT ALL PRIVILEGES ON `redditonrails_test`.`localhost` TO 'redditonrails'#'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails_development`.`localhost` TO 'redditonrails'#'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails`.`localhost` TO 'redditonrails'#'localhost' |
+------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> SELECT USER(),CURRENT_USER();
+-------------------------+-------------------------+
| USER() | CURRENT_USER() |
+-------------------------+-------------------------+
| redditonrails#localhost | redditonrails#localhost |
+-------------------------+-------------------------+
1 row in set (0.00 sec)
I don't believe your syntax is right. You're specifying:
GRANT ALL PRIVILEGES ON
redditonrails_development.localhost
The expected syntax for db-level GRANT is: ON $db.$table. Based on this, you're only granting on the table named "localhost". Change to:
GRANT ALL PRIVILEGES ON
redditonrails_development.*
It would seem that your user redditonrails has all privilages on
redditonrails_development.localhost
which would mean redditonrails_development database and localhost table. what you want is to have there
redditonrails_development.*
witch would mean you have all privilages on all tables (even the new ones you're trying to create)
or at least that's how I see it.

mysql cli: how to list all databases I have permisions to create/read/update/delete?

What command do I use on a mysql command line to see all the databases on some database server that I have permissions to? Specifically I am looking for the DBs that I have full CRUD permissions to.
mysql -e "show databases"
UPDATE:
Based on your edit, here is a query you can run against the mysql database in your server:
mysql> select Db from db where User='aj' and (select_priv='Y' and insert_priv='Y' and update_priv='Y' and delete_priv='Y');
+---------+
| Db |
+---------+
| HopeDB |
| LocusDB |
+---------+
2 rows in set (0.00 sec)