Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

schema - How do I alias a database in MySQL?

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 the database to the new name, change and deploy the code connecting to it at my leisure, and eventually remove the old alias.

If there's a better way to accomplish this please let me know.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...