<tfoot id='7duEm'></tfoot>
  • <legend id='7duEm'><style id='7duEm'><dir id='7duEm'><q id='7duEm'></q></dir></style></legend>
        <bdo id='7duEm'></bdo><ul id='7duEm'></ul>

      <small id='7duEm'></small><noframes id='7duEm'>

      <i id='7duEm'><tr id='7duEm'><dt id='7duEm'><q id='7duEm'><span id='7duEm'><b id='7duEm'><form id='7duEm'><ins id='7duEm'></ins><ul id='7duEm'></ul><sub id='7duEm'></sub></form><legend id='7duEm'></legend><bdo id='7duEm'><pre id='7duEm'><center id='7duEm'></center></pre></bdo></b><th id='7duEm'></th></span></q></dt></tr></i><div id='7duEm'><tfoot id='7duEm'></tfoot><dl id='7duEm'><fieldset id='7duEm'></fieldset></dl></div>

      1. 如何快速重命名 MySQL 数据库(更改架构名称)?

        时间:2023-08-17
      2. <i id='NkZk6'><tr id='NkZk6'><dt id='NkZk6'><q id='NkZk6'><span id='NkZk6'><b id='NkZk6'><form id='NkZk6'><ins id='NkZk6'></ins><ul id='NkZk6'></ul><sub id='NkZk6'></sub></form><legend id='NkZk6'></legend><bdo id='NkZk6'><pre id='NkZk6'><center id='NkZk6'></center></pre></bdo></b><th id='NkZk6'></th></span></q></dt></tr></i><div id='NkZk6'><tfoot id='NkZk6'></tfoot><dl id='NkZk6'><fieldset id='NkZk6'></fieldset></dl></div>
        <tfoot id='NkZk6'></tfoot>
        <legend id='NkZk6'><style id='NkZk6'><dir id='NkZk6'><q id='NkZk6'></q></dir></style></legend>
          <bdo id='NkZk6'></bdo><ul id='NkZk6'></ul>

        • <small id='NkZk6'></small><noframes id='NkZk6'>

                  <tbody id='NkZk6'></tbody>

                1. 本文介绍了如何快速重命名 MySQL 数据库(更改架构名称)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  MySQL 手册位于 MySQL 涵盖了这一点.

                  The MySQL manual at MySQL covers this.

                  通常我只是转储数据库并使用新名称重新导入它.对于非常大的数据库,这不是一个选项.显然 RENAME {DATABASE |SCHEMA} db_name TO new_db_name; 做坏事,只存在于少数版本中,总体来说是个坏主意.

                  Usually I just dump the database and reimport it with a new name. This is not an option for very big databases. Apparently RENAME {DATABASE | SCHEMA} db_name TO new_db_name; does bad things, exist only in a handful of versions, and is a bad idea overall.

                  这需要与 InnoDB 一起使用,它存储的东西与 MyISAM.

                  This needs to work with InnoDB, which stores things very differently than MyISAM.

                  推荐答案

                  对于 InnoDB,以下似乎有效:创建新的空数据库,然后依次将每个表重命名为新数据库:

                  For InnoDB, the following seems to work: create the new empty database, then rename each table in turn into the new database:

                  RENAME TABLE old_db.table TO new_db.table;
                  

                  之后您需要调整权限.

                  对于在 shell 中编写脚本,您可以使用以下任一方法:

                  For scripting in a shell, you can use either of the following:

                  mysql -u username -ppassword old_db -sNe 'show tables' | while read table; \ 
                      do mysql -u username -ppassword -sNe "rename table old_db.$table to new_db.$table"; done
                  

                  for table in `mysql -u root -ppassword -s -N -e "use old_db;show tables from old_db;"`; do mysql -u root -ppassword -s -N -e "use old_db;rename table old_db.$table to new_db.$table;"; done;
                  

                  <小时>

                  注意事项:


                  Notes:

                  • 选项 -p 和密码之间没有空格.如果您的数据库没有密码,请删除 -u username -ppassword 部分.
                  • 如果某个表有触发器,则无法使用上述方法将其移动到另一个数据库(将导致Trigger in wrong schema 错误).如果是这种情况,请使用传统方式克隆数据库,然后删除旧数据库:

                  • There is no space between the option -p and the password. If your database has no password, remove the -u username -ppassword part.
                  • If some table has a trigger, it cannot be moved to another database using above method (will result Trigger in wrong schema error). If that is the case, use a traditional way to clone a database and then drop the old one:

                  mysqldump old_db |mysql new_db

                  如果你有存储过程,你可以在之后复制它们:

                  If you have stored procedures, you can copy them afterwards:

                  mysqldump -R old_db |mysql new_db

                  这篇关于如何快速重命名 MySQL 数据库(更改架构名称)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQL - 插入后更新同一个表的触发器 下一篇:如何调试 MySQL 上超出的锁定等待超时?

                  相关文章

                  最新文章

                2. <i id='igltX'><tr id='igltX'><dt id='igltX'><q id='igltX'><span id='igltX'><b id='igltX'><form id='igltX'><ins id='igltX'></ins><ul id='igltX'></ul><sub id='igltX'></sub></form><legend id='igltX'></legend><bdo id='igltX'><pre id='igltX'><center id='igltX'></center></pre></bdo></b><th id='igltX'></th></span></q></dt></tr></i><div id='igltX'><tfoot id='igltX'></tfoot><dl id='igltX'><fieldset id='igltX'></fieldset></dl></div>

                  <legend id='igltX'><style id='igltX'><dir id='igltX'><q id='igltX'></q></dir></style></legend>

                  <small id='igltX'></small><noframes id='igltX'>

                    • <bdo id='igltX'></bdo><ul id='igltX'></ul>
                    <tfoot id='igltX'></tfoot>