How do I alias a database in MySQL?(如何在 MySQL 中为数据库设置别名?)
问题描述
我正在寻找一种在 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.
推荐答案
https://dev.mysql.com/doc/refman/5.7/en/symbolic-links-to-databases.html 说
MySQL 不支持将一个目录链接到多个数据库.
MySQL does not support linking one directory to multiple databases.
您可以使用符号链接将数据库目录链接到其他位置,例如在 datadir 之外.
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 .
但是您不能使用符号链接使一个数据库目录成为另一个 MySQL 数据库的别名":
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
原因是 InnoDB 将数据库名称和其他元数据保留在其自己的数据字典中,存储在表空间文件中.如果你混淆了它,你就得不到你想要的.
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 没有任何用于为数据库设置别名的 DDL 语法.
MySQL doesn't have any DDL syntax for aliasing a database.
这篇关于如何在 MySQL 中为数据库设置别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 MySQL 中为数据库设置别名?


- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01