Mac 启动 mysql 服务失败
问题现象
Warning:The /usr/local/mysql/data directory is not owned by the ‘mysql’ or ‘_mysql’
分析解决
这应该是某种情况下导致 /usr/local/mysql/data 的宿主发生了改变,只需要在终端运行如下命令即可。
1 | sudo chown -R mysql /usr/local/mysql/data |
Error Code: 1093
问题现象
执行如下 SQL:
1 | delete from sc where cid in (select sc.cid from sc, course c, teacher t where sc.cid = c.cid and c.tid = t.tid and t.tname = '叶平'); |
报错如下:
1 | Error Code: 1093. You can't specify target table 'sc' for update in FROM clause |
分析解决
不能先将 select 出表中的某些值,再 update/delete 这个表(在同一语句中)。多嵌套一层子查询,再进行删除,如下:
1 | delete from sc where cid in (select distinct(cid) from (select sc.cid from sc, course c, teacher t where sc.cid = c.cid and c.tid = t.tid and t.tname = '叶平') a); |
Error Code: 1175
问题现象
执行如下 SQL:
1 | delete from sc where cid in (select distinct(cid) from (select sc.cid from sc, course c, teacher t where sc.cid = c.cid and c.tid = t.tid and t.tname = '叶平') a); |
报错如下:
1 | Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect. |
分析解决
这是因为 MySQL 运行在 safe-updates 模式下,该模式会导致非主键条件下无法执行 update 或者 delete 命令。
1 | 1、show variables like 'SQL_SAFE_UPDATES'; 查看开关状态。 |