How do I alias a database in MySQL?

前端 未结 4 1267
猫巷女王i
猫巷女王i 2020-12-03 21:00

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

4条回答
  •  情歌与酒
    2020-12-03 21:38

    https://dev.mysql.com/doc/refman/5.7/en/symbolic-links-to-databases.html says

    MySQL does not support linking one directory to multiple databases.

    You can use symbolic links to link a database directory to some other location, for example outside the datadir.

    $ cd /var/lib/mysql
    $ ln -s /other/dir/mydatabase .
    

    But you can't use symbolic links to make one database directory an "alias" for another MySQL database:

    $ cd /var/lib/mysql
    $ ln -s `pwd`/mydatabase1 mydatabase2  # WRONG
    

    The reason is that InnoDB retains database names and other metadata inside its own data dictionary, stored in the tablespace file. If you confuse it, you won't get what you want.

    MySQL doesn't have any DDL syntax for aliasing a database.

提交回复
热议问题