We have a production MySQL server with the following grants:
mysql> show grants for the_db;
+------------------------------------------------------------------------------------------------------------+
| Grants for db_user@% |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'db_user'@'%' IDENTIFIED BY PASSWORD '*A236932DB5549260BDC088C4BC2F0C6DB04424D7' |
| GRANT ALL PRIVILEGES ON `xydb`.* TO 'db_user'@'%' |
| GRANT SELECT ON `xyie-db`.* TO 'db_user'@'%' |
| GRANT SELECT ON `supportdb`.* TO 'db_user'@'%' |
| GRANT SELECT ON `xbs`.* TO 'db_user'@'%' |
+------------------------------------------------------------------------------------------------------------+
Is it possible to block access to these databases for a specific host? We have a new server coming online that will be using other test databases on the same server. I don't want the new server to be able to accidentally do anything on the production databases.
I understand I can use REVOKE access, but I'm not sure if that requires altering the existing GRANTS to be more specific to the hosts that they allow. I don't want to guess as the production dbs here are in constant use and accidentally blocking access for the live host would be bad.
Ideally I need to be able to just say:
BLOCK ACCESS ON 'xydb'.* TO 'db_user'@'192.168.1.4'
I'm not sure if you can do it using
REVOKE
, but you can definitely do it by inserting an entry into the relevant table in themysql
schema:The first two lines do the heavy lifting of inserting into the DB; it's best to put both the IP and hostname in there, for clarity, while still ensuring that even if reverse lookups aren't working, the IP will still be blocked. The
FLUSH PRIVILEGES
is required because MySQL doesn't look in the tables every time it needs to know something -- it caches the info in memory. You need to tell MySQL to flush its cache.If the
xydb
could have a different mysql password on the production and test DB servers, then you can give the mysql user a "wrong" password on the live serverTo recreate your situation:
This results with the user being able to login from localhost
And then a user is added specifically for the host that will be blacklisted.
and then the user can no longer login (unless of course he gives the proper password)