We recently exported a database from one machine to another and were having issues with SELECT statements, even though we had granted all privileges to the account:
shell# mysql -u root -p
mysql> GRANT ALL ON databasename.* TO 'dbuser'@'localhost' IDENTIFIED BY 'Pa5sW0Rd'; FLUSH PRIVILEGES; EXIT;
shell# mysql -u dbuser -p
mysql> USE databasename; SELECT * FROM table;
ERROR 1045 (28000): Access denied for user 'dbuser'@'localhost' (using password: YES)
mysql>
I've never come across this before! I tried running that same SELECT statement as root and receievd a much more helpful error message:
mysql> SELECT * FROM table;
ERROR 1449 (HY000): The user specified as a definer ('dbuser'@'%') does not exist
Ah-ha! Turns out there is something called a 'definer' which is used for MySQL queries, and I didn't have an account that matched that definer: note the difference in host?
The easiest, for me, was to allow that 'dbuser'@'%' to exist, since MySQL is behind a few firewalls anyways:
shell# mysql -u root -p
mysql> GRANT ALL ON databasename.* TO 'dbuser'@'%' IDENTIFIED BY 'Pa5sW0Rd'; FLUSH PRIVILEGES; EXIT;
Thanks for the tip, Patrick.Kelly!
shell# mysql -u root -p
mysql> GRANT ALL ON databasename.* TO 'dbuser'@'localhost' IDENTIFIED BY 'Pa5sW0Rd'; FLUSH PRIVILEGES; EXIT;
shell# mysql -u dbuser -p
mysql> USE databasename; SELECT * FROM table;
ERROR 1045 (28000): Access denied for user 'dbuser'@'localhost' (using password: YES)
mysql>
I've never come across this before! I tried running that same SELECT statement as root and receievd a much more helpful error message:
mysql> SELECT * FROM table;
ERROR 1449 (HY000): The user specified as a definer ('dbuser'@'%') does not exist
Ah-ha! Turns out there is something called a 'definer' which is used for MySQL queries, and I didn't have an account that matched that definer: note the difference in host?
The easiest, for me, was to allow that 'dbuser'@'%' to exist, since MySQL is behind a few firewalls anyways:
shell# mysql -u root -p
mysql> GRANT ALL ON databasename.* TO 'dbuser'@'%' IDENTIFIED BY 'Pa5sW0Rd'; FLUSH PRIVILEGES; EXIT;
Thanks for the tip, Patrick.Kelly!