Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...