Renaming or Moving a MySQL Database and User

This article covers the renaming the name of a database as well as the user who has privileges on that database. For my example, I am renaming the database from old_db to new_db and also renaming the user old_user to new_user:

Update the mysql database:

shell> mysql -u root -p
mysql> USE mysql;
mysql> UPDATE user SET User='new_user' WHERE User='old_user';
mysql> UPDATE db SET Db='new_db',User='new_user' WHERE User='old_user' AND Db='old_db';
mysql> exit

Find the database location (usually in /usr/local/mysql/data):

sudo find /usr -name "old_db" -type d

Stop the MySQL server, move the database, re-start the MySQL server on Mac OS X:

sudo su -
cd /usr/local/mysql/data
../support-files/mysql.server stop
mv old_db new_db
../support-files/mysql.server start

Comments are closed.