# \#MySQL

**URL:** https://www.shiqidu.com/tag/90-tag/90.md

[最新](https://www.shiqidu.com/latest.md) · [类别](https://www.shiqidu.com/categories.md) · [标签](https://www.shiqidu.com/tags.md)

---

## [MySQL更新json字段，添加key。](https://www.shiqidu.com/t/topic/887)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2026 年1 月 21 日 03:29 UTC](https://www.shiqidu.com/t/topic/887 "2026-01-21T03:29:54Z")

</div>

如果我的order表，extend\_info字段类型是text，但是存储的内容是json格式的字符串，且字段允许为null，我想给extend\_info字段新增一个key，fromStockMerge，值为1。 { "a": "1…

---

## [mysql之日志系统：SQL更新语句逻辑](https://www.shiqidu.com/t/topic/866)

<div class="topic-metadata">

**Author:** [@caijizhushou](https://www.shiqidu.com/u/caijizhushou)\
**回复:** 0\
**最近更新：:** [2025 年11 月 6 日 15:45 UTC](https://www.shiqidu.com/t/topic/866 "2025-11-06T15:45:53Z")

</div>

mysql的2个重要日志：物理日志redo log和逻辑日志 binlog。 redo log: 保证crash-safe能力 每次事务的redo log持久化到磁盘：innodb\_flush\_log\_at\_trx\_commit=1 …

---

## [踩坑，PDO的commit方法就算数据库down了也不会返回false。](https://www.shiqidu.com/t/topic/815)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2024 年5 月 17 日 09:08 UTC](https://www.shiqidu.com/t/topic/815 "2024-05-17T09:08:06Z")

</div>

如题，不要依赖这个commit()方法的返回值，测试发现在commit执行前把mysql关闭，此函数还是会返回true，只是脚本会抛出一个warning级别的警告信息。 及时pdo的errormode设置的是 ERRMODE\_EXC…

---

## [macOS brew 安装两个版本的MySQL](https://www.shiqidu.com/t/topic/814)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2024 年5 月 17 日 02:59 UTC](https://www.shiqidu.com/t/topic/814 "2024-05-17T02:59:04Z")

</div>

brew 默认安装的MySQL版本是最新版，但是因为测试需要，得安装一个5.7版本的，brew search mysql之后，看到了mysql@5.7。 ==\> Formulae automysqlbackup …

---

## [MySQL 踩坑之 datetime 字段比较。](https://www.shiqidu.com/t/topic/809)

<div class="topic-metadata">

**Author:** [@caojie](https://www.shiqidu.com/u/caojie)\
**回复:** 0\
**最近更新：:** [2024 年3 月 13 日 13:56 UTC](https://www.shiqidu.com/t/topic/809 "2024-03-13T13:56:22Z")

</div>

表 order 有字段 paidtime 类型为 datetime，现在要筛选2月份的订单，所以写了SQL 如下。 select id from order where paidtime \>= '2024-02-01 00:00:00' …

---

## [MySQL JSON字段查询](https://www.shiqidu.com/t/topic/808)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2024 年3 月 11 日 12:00 UTC](https://www.shiqidu.com/t/topic/808 "2024-03-11T12:00:00Z")

</div>

JSON字段是单对象 SELECT json\_column-\>"$.key" FROM your\_table; 或 SELECT JSON\_EXTRACT(json\_column, '$.key') as key FROM your\_t…

---

## [MySQL8修改root密码报错 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements](https://www.shiqidu.com/t/topic/798)

<div class="topic-metadata">

**Author:** [@caojie](https://www.shiqidu.com/u/caojie)\
**回复:** 0\
**最近更新：:** [2023 年7 月 27 日 03:46 UTC](https://www.shiqidu.com/t/topic/798 "2023-07-27T03:46:40Z")

</div>

本地的MySQL，改不了root密码，报错如下。 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 字面意思，输入的密码…

---

## [下面的SQL有什么问题？](https://www.shiqidu.com/t/topic/794)

<div class="topic-metadata">

**Author:** [@caojie](https://www.shiqidu.com/u/caojie)\
**回复:** 0\
**最近更新：:** [2023 年4 月 11 日 10:15 UTC](https://www.shiqidu.com/t/topic/794 "2023-04-11T10:15:41Z")

</div>

---

## [MySQL从大表（千万级）中删除符合条件的记录的可用方法。](https://www.shiqidu.com/t/topic/769)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 2\
**最近更新：:** [2022 年5 月 17 日 09:18 UTC](https://www.shiqidu.com/t/topic/769 "2022-05-17T09:18:55Z")

</div>

我有一个日志表 user\_log，大概有6000万数据。表中存在大量无用数据。比如 status = 2 的数据是垃圾数据（status加了索引），永远都不会被查询或修改，所以我想把这部分记录删除掉，节省点表空间。这部分无用数据大概是200…

---

## [MySQL删除表中大量数据后，表空间大小不变的解决方案。](https://www.shiqidu.com/t/topic/766)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2022 年1 月 14 日 03:23 UTC](https://www.shiqidu.com/t/topic/766 "2022-01-14T03:23:49Z")

</div>

有一个表有5000万+的数据，其中很多数据没有用了，想着通过删除无用的数据来达到节省表空间的目的，删了几百万条后发现，表空间大小并不会改变。 原因 我的删除命令如下 delete from tb where condition = 'a…

---

## [浅谈MySQL的四种隔离级别](https://www.shiqidu.com/t/topic/751)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2021 年7 月 13 日 10:02 UTC](https://www.shiqidu.com/t/topic/751 "2021-07-13T10:02:10Z")

</div>

众所周知，MySQL的四种隔离级别分别是 READ UNCOMMITTED （读未提交） READ COMMITTED （读已提交） REPEATABLE READ （可重复读） SERIALIZABLE （串行化） 从上到下，隔离的…

---

## [MySQL计算两坐标之间的距离，查询某个点附近的数据根据距离排序。](https://www.shiqidu.com/t/topic/749)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2021 年7 月 5 日 04:09 UTC](https://www.shiqidu.com/t/topic/749 "2021-07-05T04:09:14Z")

</div>

产品有个需求是查出当前用户附近的餐厅，记录一下： SELECT id, \`name\`, lat, lng, 6378.138 \* 2 \* ASIN( SQRT( POW( SIN( ( 40.0041236877441…

---

## [MySQL group by 统计每5分钟数据量](https://www.shiqidu.com/t/topic/724)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 3\
**最近更新：:** [2021 年5 月 18 日 15:11 UTC](https://www.shiqidu.com/t/topic/724 "2021-05-18T15:11:47Z")

</div>

需求 有打卡记录表结构如下 ID user\_id (int) create\_time (int) 1 123 1603209599 现需要统计每5分钟的记录数量，按记录数量降序排列 分析 关键在于怎么把create…

---

## [MySQL 连接查询时 where 和 on 的区别](https://www.shiqidu.com/t/topic/738)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2021 年5 月 12 日 15:24 UTC](https://www.shiqidu.com/t/topic/738 "2021-05-12T15:24:06Z")

</div>

两个SQL，第一个能查询出正常结果，第二个不能。 正确的SQL SELECT tmp.\*, cpr.id, cpr.repeat\_times FROM ( SELECT MIN( remind\_time ) AS remind\_…

---

## [MySQL8 开始慢查询日志，并记录到表中。](https://www.shiqidu.com/t/topic/737)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2021 年4 月 28 日 01:45 UTC](https://www.shiqidu.com/t/topic/737 "2021-04-28T01:45:57Z")

</div>

SHOW VARIABLES LIKE '%slow\_query%'; SET GLOBAL log\_output = 'TABLE'; -- 开启慢日志,纪录到 mysql.slow\_log 表 SET GLOBAL long\_qu…

---

## [MySQL删除重复数据](https://www.shiqidu.com/t/topic/729)

<div class="topic-metadata">

**Author:** [@caojie](https://www.shiqidu.com/u/caojie)\
**回复:** 1\
**最近更新：:** [2021 年3 月 21 日 10:05 UTC](https://www.shiqidu.com/t/topic/729 "2021-03-21T10:05:28Z")

</div>

DELETE w FROM subscribe\_msg\_list w RIGHT JOIN ( SELECT \*, count(1) AS cc FROM subscribe\_msg\_list GROUP BY type, user\_id,…

---

## [MySQL 函数 substring\_index 的用法](https://www.shiqidu.com/t/topic/731)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2021 年1 月 19 日 09:10 UTC](https://www.shiqidu.com/t/topic/731 "2021-01-19T09:10:27Z")

</div>

substring\_index（“待截取有用部分的字符串”，“截取数据依据的字符”，截取字符的位置N） 案例 SELECT SUBSTRING\_INDEX(‘15,151,152,16’, ’ , ’ , 1); // 结果是15 以第…

---

## [MySQL 更改表结构会导致锁表吗？](https://www.shiqidu.com/t/topic/726)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2020 年11 月 24 日 08:05 UTC](https://www.shiqidu.com/t/topic/726 "2020-11-24T08:05:24Z")

</div>

自5.6以后，单纯增加字段是不会导致锁表的，但是如果更改字段类型是会导致锁表的，具体可以通过下表查询哪些DDL语句和DML是不允许并发的。 主键操作是否允许与DML语句并发。 官方文档：https://dev.mysql.c…

---

## [记一次MySQL order by 踩坑记录](https://www.shiqidu.com/t/topic/725)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2020 年10 月 31 日 02:58 UTC](https://www.shiqidu.com/t/topic/725 "2020-10-31T02:58:46Z")

</div>

需求 分页+排序 表结构 表行数 1000万+ 事故重现 原SQL SELECT \* FROM clearplate\_users\_log WHERE state = 3 ORDER BY create\_time ASC LIMIT…

---

## [MySQL order by 和 limit 做分页时，数据重复的问题](https://www.shiqidu.com/t/topic/716)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 2\
**最近更新：:** [2020 年9 月 11 日 06:32 UTC](https://www.shiqidu.com/t/topic/716 "2020-09-11T06:32:46Z")

</div>

有一SQL如下 SELECT cu.monthly\_clearplate\_num, cu.clearplate\_num, gr.user\_id FROM \`group\_users\_relation\` AS gr LEFT JO…

---

## [PDO获取记录行数](https://www.shiqidu.com/t/topic/714)

<div class="topic-metadata">

**Author:** [@yeqiu](https://www.shiqidu.com/u/yeqiu)\
**回复:** 1\
**最近更新：:** [2020 年9 月 2 日 08:17 UTC](https://www.shiqidu.com/t/topic/714 "2020-09-02T08:17:07Z")

</div>

SQL如下 select \* from \`users\` where create\_time \>= '2020-06-01 00:00:00' 使用 rowCount() 方法是错误的，rowCount() 返回的是受影响行数。正确的做法…

---

## [MySQL count(\*) 和 count(1) 谁更快](https://www.shiqidu.com/t/topic/710)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2020 年7 月 18 日 07:18 UTC](https://www.shiqidu.com/t/topic/710 "2020-07-18T07:18:32Z")

</div>

count(\*) 和 count(1) 没有区别， 在InnoDB引擎中速度会比MyISAM慢，因为MyISAM会缓存数据条数，查询时直接取出，InnoDB则不会，需要遍历每行数据。

---

## [MySQL启动报错 Starting MySQL.. ERROR! The server quit without updating PID file](https://www.shiqidu.com/t/topic/703)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2020 年6 月 23 日 04:49 UTC](https://www.shiqidu.com/t/topic/703 "2020-06-23T04:49:02Z")

</div>

刚刚发现MySQL挂了，然后重启MySQL的时候遇到下面的错。 # /etc/init.d/mysql start Starting MySQL.. ERROR! The server quit without updating PID …

---

## [一条MySQL语句查出类似QQ的最近联系人列表](https://www.shiqidu.com/t/topic/128)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 13\
**最近更新：:** [2020 年6 月 3 日 10:09 UTC](https://www.shiqidu.com/t/topic/128 "2020-06-03T10:09:48Z")

</div>

本站使用Swoole做了类似QQ的聊天功能，（点击用户头像或名称，进入用户主页，在用户主页点击“发私信”按钮进入聊天界面），可与其他会员即时聊天，聊天功能暂不详述，下面说说遇到的问题。我想在聊天窗口右侧，显示用户的最近联系人列表，如下图所示…

---

## [MySQL 排它锁 详解 \[转\]](https://www.shiqidu.com/t/topic/650)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2019 年9 月 30 日 04:55 UTC](https://www.shiqidu.com/t/topic/650 "2019-09-30T04:55:48Z")

</div>

Mysql InnoDB 排他锁 用法 : select … for update; 例如 : select \* from goods where id = 1 for update; 排他锁的申请前提 : 没有线程对该结果集中的任…

---

## [SELECT /\*!40001 SQL\_NO\_CACHE \*/ \* FROM mytable](https://www.shiqidu.com/t/topic/642)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2019 年9 月 17 日 06:40 UTC](https://www.shiqidu.com/t/topic/642 "2019-09-17T06:40:38Z")

</div>

在慢查询报警日志中发现很多这种语法，意思是如果 MySQL 版本 \>= 4.0.1，则执行 SELECT SQL\_NO\_CACHE \* FROM mytable，mysqldump 会使用这种语法，所以数据备份会引起这个问题。 附 MyS…

---

## [SQL面试题：行列如何互换？](https://www.shiqidu.com/t/topic/609)

<div class="topic-metadata">

**Author:** [@yeqiu](https://www.shiqidu.com/u/yeqiu)\
**回复:** 0\
**最近更新：:** [2019 年7 月 26 日 16:13 UTC](https://www.shiqidu.com/t/topic/609 "2019-07-26T16:13:29Z")

</div>

【面试题】下面是学生的成绩表（表名score，列名：学号、课程号、成绩） 使用sql实现将该表行转列为下面的表结构 【解答】 第1步，使用常量列输出目标表的结构 可以看到查询结果已经和目标表非常接近了 select 学号…

---

## [MySQL 联合索引 最左匹配原则](https://www.shiqidu.com/t/topic/607)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 2\
**最近更新：:** [2019 年7 月 25 日 17:25 UTC](https://www.shiqidu.com/t/topic/607 "2019-07-25T17:25:00Z")

</div>

---

## [一条SQL删除数据表中的重复数据](https://www.shiqidu.com/t/topic/533)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2018 年12 月 17 日 11:02 UTC](https://www.shiqidu.com/t/topic/533 "2018-12-17T11:02:04Z")

</div>

表中数据如下 要求删除后出现的重复的数据，即删掉ID为3的数据。 方式一 delete p1 from duplicate\_email as p1,duplicate\_email as p2 where p1.email = p2…

---

## [MySQL通过子查询更新](https://www.shiqidu.com/t/topic/526)

<div class="topic-metadata">

**Author:** [@Eureka](https://www.shiqidu.com/u/Eureka)\
**回复:** 0\
**最近更新：:** [2018 年12 月 6 日 01:36 UTC](https://www.shiqidu.com/t/topic/526 "2018-12-06T01:36:02Z")

</div>

一般情况下可能会直接上来这么写 update sqd\_a set amount = amount \* 0.1 where id in (select id from sqd\_b where is\_dividend = 1 and get\_…

[下一页](https://www.shiqidu.com/tag/90-tag/90.md?match_all_tags=true&page=1&tags%5B%5D=MySQL)
