MySQL Error Code 1133 – Can’t Find Any Matching Row in User Table

MySQLusers

Im reading O'Relly "Learning MySQL" and it says that you can create a user in MySQL by doing just this:

mysql> GRANT ALL ON *.* TO 'jill'@'%.invyhome.com' IDENTIFIED BY 'the_password';
Query OK, 0 rows affected (0.01 sec)

But if I try to do:

-> grant select on testgrounds.personas to ''@'localhost';
--> Error Code: 1133. Can't find any matching row in the user table

But it succeds if I use a password:

->grant select on testgrounds.personas to ''@'localhost' identified by 'pass';
--> 0 row(s) affected

I had to restore the privileges for user root because i was experimenting and i messed them up, so i think before doing that i could actually use the statement in the book (i dont remember 100%)

-> select current_user;
--> 'root@localhost'

-> show grants;
--> 'GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'localhost\' IDENTIFIED BY PASSWORD \'*4ACFE3202A5FF5CF467898FC58AAB1D615029441\' WITH GRANT OPTION'
--> 'GRANT ALL PRIVILEGES ON `testgrounds`.* TO \'root\'@\'localhost\' WITH GRANT OPTION'
--> 'GRANT PROXY ON \'\'@\'\' TO \'root\'@\'localhost\' WITH GRANT OPTION'

Is there something wrong with my MySQL installation or set-up?

Best Answer

This is not a problem with MySQL installation or set-up.

Each account name consists of both a user and host name like 'user_name'@'host_name', even when the host name is not specified. From the MySQL Reference Manual:

MySQL account names consist of a user name and a host name. This enables creation of accounts for users with the same name who can connect from different hosts.

This also allows MySQL to grant different levels of permissions depending on which host they use to connect.

When updating grants for an account where MySQL doesn't recognize the host portion, it will return an error code 1133 unless if it has a password to identify this account.

Also, MySQL will allow an account name to be specified only by it's user name, but in this case it is treated as 'user_name'@'%'.