I have multiple mysql databases and I want to perform some administration tasks on a particular database. How do I ensure that no one else can connect to that database while
Apparently, you can use the FLUSH command for this as such:
>
FLUSH TABLES WITH READ LOCK;
and then
>
UNLOCK TABLES;
to unlock the database again. Unsure if some setting needs to be set on the tables to allow a readlock. You can test this by trying to do a manual insert after the database is locked and if you get an error message about the table being locked, you know it worked.
More information on FLUSH command
You have a couple of options, as I see it:
Shutdown mysqld
, the daemon that connections to be established to databases. This has the downside of preventing access to all the mysql databases on that computer.
Move the file or change the access permissions to it, so that only your user may work with it. (I have no idea if this will work.) The database files are located somewhere like /var/lib/mysql
. Just don't forget when you're done to change them back to something that mysqld
will be able to work with!
Good luck!
If you can afford stopping the server for the time of maintenance, stop the daemon and reconfigure it to not listen to network connections. Only allow connections through a local UNIX socket.
Then logon locally on the same machine, either physically or via SSH. As long as nobody else has access to the machine, this will ensure you are alone. When done, restore the original configuration file and restart the daemon.
A different approach would be to temporarily disable all user accounts but "root" (or whatever you use to do your maintenance) for the particular database. This has the drawback however of actually messing with account data which is a little more risky than just preventing network connections.