Mysql refresh

本文详细解析了MySQL中KEY、INDEX、UNIQUE、PRIMARY和FULL-TEXT索引的区别,阐述了它们各自的功能、特点及使用场景。特别强调了FULL-TEXT索引仅适用于全文搜索,而其他索引通常用于加速查询、确保数据一致性。

Mysql Refresh

1. KEY,INDEX,UNIQUE,PRIMARY,FULL-TEXT区别

 

Differences

  • KEY or INDEX refers to a normal non-unique index. Non-distinct values for the index are allowed, so the index may contain rows with identical values in all columns of the index. These indexes don't enforce any restraints on your data so they are used only for making sure certain queries can run quickly.

  • UNIQUE refers to an index where all rows of the index must be unique. That is, the same row may not have identical non-NULL values for all columns in this index as another row. As well as being used to speed up queries, UNIQUE indexes can be used to enforce restraints on data, because the database system does not allow this distinct values rule to be broken when inserting or updating data.

    Your database system may allow a UNIQUE index to be applied to columns which allow NULL values, in which case two rows are allowed to be identical if they both contain a NULL value (the rationale here is that NULL is considered not equal to itself). Depending on your application, however, you may find this undesirable: if you wish to prevent this, you should disallow NULL values in the relevant columns.

  • PRIMARY acts exactly like a UNIQUE index, except that it is always named 'PRIMARY', and there may be only one on a table (and there should always be one; though some database systems don't enforce this). A PRIMARY index is intended as a primary means to uniquely identify any row in the table, so unlike UNIQUE it should not be used on any columns which allow NULL values. Your PRIMARY index should be on the smallest number of columns that are sufficient to uniquely identify a row. Often, this is just one column containing a unique auto-incremented number, but if there is anything else that can uniquely identify a row, such as "countrycode" in a list of countries, you can use that instead.

    Some database systems (such as MySQL's InnoDB) will store a table's records on disk in the order in which they appear in the PRIMARY index.

  • FULLTEXT indexes are different from all of the above, and their behaviour differs significantly between database systems. FULLTEXT indexes are only useful for full text searches done with the MATCH() / AGAINST() clause, unlike the above three - which are typically implemented internally using b-trees (allowing for selecting, sorting or ranges starting from left most column) or hash tables (allowing for selection starting from left most column).

    Where the other index types are general-purpose, a FULLTEXT index is specialised, in that it serves a narrow purpose: it's only used for a "full text search" feature.

Similarities

  • All of these indexes may have more than one column in them.

  • With the exception of FULLTEXT, the column order is significant: for the index to be useful in a query, the query must use columns from the index starting from the left - it can't use just the second, third or fourth part of an index, unless it is also using the previous columns in the index to match static values. (For a FULLTEXT index to be useful to a query, the query must use all columns of the index.)

 

总结一下,都是索引所以不用重复在一个列上使用多个以上关键字。full-text用在full text search 所以一般情况下不常用。

 

 

-------------------------------------------------------------------------------------------------------------------

合并操作可以减少阻塞和操作时间

ALTER TABLE XXX
ADD INDEX (xxx),
ADD INDEX (xxx2);

 

 

运行时更改表会阻塞除了SELECT之外的操作。
高可用性容错度高的主表复制技术来支持在线变更表结构,比如
oak-online-alter-table
以及facebook的在线变更工具OSC

 

 

 

 

 

 

<think>好的,用户想了解如何刷新MySQL的相关操作,也就是“mysql refresh operation or command”。首先,我需要明确“刷新”在MySQL中的具体含义。通常用户可能指的是刷新权限、刷新日志、或者清除缓存等操作。 先回想一下MySQL的常见刷新命令。记得FLUSH命令是关键,它可以用来刷新各种系统状态,比如权限、日志、缓存等。根据引用[3],提到了SHUTDOWN权限,虽然这和刷新无关,但可能需要相关权限来执行某些FLUSH操作。需要确认用户是否有足够的权限执行这些命令。 然后,用户可能需要刷新权限,比如在修改了用户权限后,使用FLUSH PRIVILEGES。这个命令会重新加载授权表,使更改立即生效。引用[1]中提到了启动MySQL的命令,但用户可能需要知道如何在不重启的情况下应用更改,所以FLUSH PRIVILEGES很重要。 接下来是刷新日志文件,比如二进制日志或错误日志。使用FLUSH LOGS可以轮换日志文件,方便管理和备份。这也是常见的维护操作。 另外,刷新缓存,比如查询缓存或表缓存,可以用FLUSH QUERY CACHE或者RESET QUERY CACHE。不过需要注意,查询缓存在MySQL 8.0中已经被移除了,所以如果用户使用的是较新版本,这部分可能需要调整。 还有,可能需要刷新表的状态,比如FLUSH TABLES会关闭所有打开的表并清空查询缓存。这在某些情况下可以释放资源或解决表锁定问题。 用户可能还需要知道如何通过命令行工具执行这些命令,比如使用mysqladmin工具。例如,mysqladmin flush-privileges对应FLUSH PRIVILEGES。引用[1]中提到了启动和停止MySQL的命令,可能用户有系统管理的需求,所以提供命令行示例会有帮助。 此外,引用[3]提到需要SHUTDOWN权限,但FLUSH命令通常需要RELOAD权限。所以需要提醒用户确保执行命令的账户有足够的权限,比如RELOAD和可能的其他权限。 还要考虑用户可能遇到的错误情况,比如权限不足时的提示,或者版本差异导致的命令不可用。例如,在MySQL 8.0中,查询缓存相关命令已经不存在,需要指出这一点。 最后,生成相关问题时要覆盖权限管理、日志管理、缓存优化等方面,帮助用户全面了解相关操作。</think>### MySQL刷新操作详解 MySQL中"刷新"操作主要用于实时更新系统状态或缓存,常用命令为$FLUSH$,需配合$RELOAD$权限执行[^3]。以下是具体操作分类: 1. **权限刷新** ```sql FLUSH PRIVILEGES; -- 修改用户权限后强制重载授权表 ``` 等价命令行: ```bash mysqladmin flush-privileges ``` 2. **日志刷新** ```sql FLUSH LOGS; -- 关闭当前日志文件并新建,适用于二进制日志/错误日志 FLUSH BINARY LOGS; -- 专门刷新二进制日志 ``` 3. **缓存刷新** ```sql FLUSH QUERY CACHE; -- 整理查询缓存(注意:MySQL 8.0已移除查询缓存) RESET QUERY CACHE; -- 清空查询缓存(同样不适用于8.0+) ``` 4. **表状态刷新** ```sql FLUSH TABLES; -- 关闭所有打开的表并清除查询缓存 FLUSH TABLES table_name; -- 指定表刷新 ``` 5. **高级刷新** ```sql FLUSH HOSTS; -- 清空host_cache表,解决连接错误 FLUSH STATUS; -- 重置状态计数器 ``` **操作权限验证:** ```sql SHOW GRANTS; -- 确认当前用户是否有RELOAD权限 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值