I\'m looking for a way to alias a database in MySQL. The reason is to be able to rename a live, production database without bringing the system down. I figure I can alias
On Unix, the way to symlink a database is first to create a directory on some disk where you have free space and then to create a soft link to it from the MySQL data directory.
shell> mkdir /dr1/databases/test
shell> ln -s /dr1/databases/test /path/to/datadir
MySQL does not support linking one directory to multiple databases. Replacing a database directory with a symbolic link works as long as you do not make a symbolic link between databases. Suppose that you have a database db1 under the MySQL data directory, and then make a symlink db2 that points to db1:
shell> cd /path/to/datadir
shell> ln -s db1 db2
The result is that, or any table tbl_a in db1, there also appears to be a table tbl_a in db2. If one client updates db1.tbl_a and another client updates db2.tbl_a, problems are likely to occur.
To determine the location of your data directory, use this statement:
SHOW VARIABLES LIKE 'datadir';
Source: http://dev.mysql.com/doc/refman/5.1/en/symbolic-links.html
Warning: Not working with MyISAM tables
1) Determine the location of your data directory:
echo "SHOW VARIABLES LIKE 'datadir';" | mysql -u root -p
2) Go to location of your data directory and stop mysql service:
sudo su
service mysql stop
cd path/to/datadir
3) Create a soft link:
ln -s current_db db_alias
4) Fix permisions:
chown -R mysql:mysql db_alias
5) Start mysql:
service mysql start