Tag Archives: mysql

Lock all MySQL databases

Lock a database:
$ mysql -u user -p
mysql> FLUSH TABLES WITH READ LOCK;
This closes all open tables and locks all tables for all databases with a read lock until you execute UNLOCK TABLES.

Unlock:
mysql> UNLOCK TABLES;

(to lock a single table: LOCK TABLES table READ;)

Recover mysql root password

– Stop mysql
# /etc/init.d/mysql stop

– Lauch mysql with –skip-grant-tables (WARNING: your mysql server will launch without any password authentication, so please protect it first with a firewall or something if it’s world accessible)
# mysqld_safe --skip-grant-tables

– Login as root without a password
$ mysql -u root

– Change the password
mysql> use mysql;
mysql> update user set password=PASSWORD("your_new_root_password") where User='root';
mysql> flush privileges;
mysql> quit

– Stop mysql
# /etc/init.d/mysql stop

– Start mysql again to re-enable authentication
# /etc/init.d/mysql start