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

  • <small id='98HBm'></small><noframes id='98HBm'>

    <legend id='98HBm'><style id='98HBm'><dir id='98HBm'><q id='98HBm'></q></dir></style></legend>
    <tfoot id='98HBm'></tfoot>
      <bdo id='98HBm'></bdo><ul id='98HBm'></ul>

      1. 如何重命名 MySQL 中的索引

        How do I rename an Index in MySQL(如何重命名 MySQL 中的索引)
        <tfoot id='ZxoUN'></tfoot>
          <bdo id='ZxoUN'></bdo><ul id='ZxoUN'></ul>

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

            <tbody id='ZxoUN'></tbody>
          • <i id='ZxoUN'><tr id='ZxoUN'><dt id='ZxoUN'><q id='ZxoUN'><span id='ZxoUN'><b id='ZxoUN'><form id='ZxoUN'><ins id='ZxoUN'></ins><ul id='ZxoUN'></ul><sub id='ZxoUN'></sub></form><legend id='ZxoUN'></legend><bdo id='ZxoUN'><pre id='ZxoUN'><center id='ZxoUN'></center></pre></bdo></b><th id='ZxoUN'></th></span></q></dt></tr></i><div id='ZxoUN'><tfoot id='ZxoUN'></tfoot><dl id='ZxoUN'><fieldset id='ZxoUN'></fieldset></dl></div>
            1. <legend id='ZxoUN'><style id='ZxoUN'><dir id='ZxoUN'><q id='ZxoUN'></q></dir></style></legend>

                  本文介绍了如何重命名 MySQL 中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想重命名一个索引.我看过 alter table 文档,但是我无法弄清楚简单地重命名索引的语法.通过 MySQL GUI 执行此操作时,它会删除索引并创建一个新索引.虽然这有效,但我想避免重建整个索引只是为了更改索引的名称.

                  I would like to rename an index. I've looked at the alter table documentation, but I can't figure out the syntax to simply rename an index. When doing it through the MySQL GUI, it drops the index, and creates a new one. While this works, I would like to avoid rebuilding the entire index just to change the name of an index.

                  [附加信息]

                  在alter table 文档中说明

                  In the alter table documentation it states

                  只修改表的改动元数据而不是表数据可以立即通过更改表的 .frm 文件并且不接触表内容.以下变化是可以进行的快速更改这样:

                  Alterations that modify only table metadata and not table data can be made immediately by altering the table's .frm file and not touching table contents. The following changes are fast alterations that can be made this way:

                  * Renaming a column or index.
                  

                  但是,当我尝试通过编辑 .frm 文件(在测试数据库上)并重新启动服务器来重命名索引时,它现在在尝试列出列时在 UI 中指出无法获取列",以及何时尝试运行查询时,它返回错误未知表引擎''"..frm 文件有很多二进制内容.有没有好的编辑二进制信息的工具.

                  However, when I tried to rename the index by editing the .frm file (on a test database) and restarting the server, it now states "Could not fetch columns" in the UI when trying to list the columns, and when trying to run a query, it returns the error "Unknown table engine ''". The .frm file has a lot of binary content. Is there a good tool for editing the binary info.

                  推荐答案

                  我在 2009 年回答过这个问题.当时 MySQL 中没有重命名索引的语法.

                  I answered this question in 2009. At that time there was no syntax in MySQL to rename an index.

                  从那时起,MySQL 5.7 引入了 ALTER TABLE RENAME INDEX 语法.

                  Since then, MySQL 5.7 introduced an ALTER TABLE RENAME INDEX syntax.

                  http://dev.mysql.com/doc/refman/5.7/en/alter-table.html 部分说:

                  • RENAME INDEX old_index_name TO new_index_name 重命名索引.这是标准 SQL 的 MySQL 扩展.表的内容保持不变.old_index_name 必须是表中现有索引的名称,该索引不会被同一 ALTER TABLE 语句删除.new_index_name 是新的索引名称,在应用更改后不能与结果表中的索引名称重复.两个索引名称都不能是 PRIMARY.
                  • RENAME INDEX old_index_name TO new_index_name renames an index. This is a MySQL extension to standard SQL. The content of the table remains unchanged. old_index_name must be the name of an existing index in the table that is not dropped by the same ALTER TABLE statement. new_index_name is the new index name, which cannot duplicate the name of an index in the resulting table after changes have been applied. Neither index name can be PRIMARY.

                  早期版本的 MySQL,例如5.6 及更早版本,不支持 ALTER TABLE 重命名索引(或键,它是同义词).

                  Earlier versions of MySQL, e.g. 5.6 and earlier, support no syntax in ALTER TABLE to rename an index (or key, which is a synonym).

                  唯一的解决方案是ALTER TABLE DROP KEY oldkeyname, ADD KEY newkeyname (...).

                  MySQL 中没有 ALTER INDEX 命令.你只能DROP INDEX 然后 CREATE INDEX 使用新名称.

                  There is no ALTER INDEX command in MySQL. You can only DROP INDEX and then CREATE INDEX with the new name.

                  关于您上面的更新:也许文档不够精确.无论如何,没有重命名索引的 SQL 语法.

                  Regarding your update above: perhaps the documentation isn't precise enough. Regardless, there's no SQL syntax to rename an index.

                  索引是一种可以从数据重建的数据结构(实际上建议使用OPTIMIZE TABLE定期重建索引).这需要一些时间,但这是一个司空见惯的操作.索引数据结构与表数据分离,因此添加或删除索引不需要触及表数据,如文档所述.

                  An index is a data structure that can be rebuilt from the data (in fact it's recommended to rebuild indexes periodically with OPTIMIZE TABLE). It takes some time, but it's a commonplace operation. Indexes data structures are separate from table data, so adding or dropping an index shouldn't need to touch the table data, as the documentation says.

                  关于.frm文件,MySQL不支持编辑.frm文件.我不会出于任何原因这样做.您 100% 保证会损坏您的表并使其无法使用.

                  Regarding the .frm file, MySQL does not support editing the .frm file. I wouldn't do it for any reason. You are 100% guaranteed to corrupt your table and make it unusable.

                  这篇关于如何重命名 MySQL 中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                    <tbody id='daB3m'></tbody>

                  <i id='daB3m'><tr id='daB3m'><dt id='daB3m'><q id='daB3m'><span id='daB3m'><b id='daB3m'><form id='daB3m'><ins id='daB3m'></ins><ul id='daB3m'></ul><sub id='daB3m'></sub></form><legend id='daB3m'></legend><bdo id='daB3m'><pre id='daB3m'><center id='daB3m'></center></pre></bdo></b><th id='daB3m'></th></span></q></dt></tr></i><div id='daB3m'><tfoot id='daB3m'></tfoot><dl id='daB3m'><fieldset id='daB3m'></fieldset></dl></div>
                • <tfoot id='daB3m'></tfoot>
                  <legend id='daB3m'><style id='daB3m'><dir id='daB3m'><q id='daB3m'></q></dir></style></legend>
                  1. <small id='daB3m'></small><noframes id='daB3m'>

                          <bdo id='daB3m'></bdo><ul id='daB3m'></ul>