【MySQL】故障汇总日志 01

Could not connect, server may not be running. Can’t connect to MySQL server on ‘localhost’ (10061)

原因:MySQL服务未启动。
解决:此电脑->右键管理->服务与应用程序->服务->找到MySQL->点击启动。

ERROR 3780 (HY000): Referencing column ‘Department_id’ and referenced column ‘Department_id’ in foreign key constraint ‘teacher_department’ are incompatible.

原因:外键约束引用列与引用列不兼容
解决:导致这个错误的原因有很多,这里优先考虑默认字符集不同。

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (course.classes, CONSTRAINT fk_cla_depart FOREIGN KEY (Department_id) REFERENCES department (Department_id))

原因:外键约束检查不存在导致的错误。
解决:先去外键约束指向的表中添加相应数据

mysql> delete from department where department_id=‘202’;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (course.classes, CONSTRAINT fk_cla_depart FOREIGN KEY (Department_id) REFERENCES department (Department_id))

原因:子表中存在id=202
解决:先删除department与classes间的外键约束,然后添加约束并将级联选项设置为cascade。
———————————————————————————————————————

delete from Person where Id in (select a.Id from Person a, Person b where a.Email=b.Email and  a.Id>b.Id);

MySql报错: You can’t specify target table ‘table name’ for update in FROM clause

错误提示:不能在同一语句中select出表中的某些值,再update这个表。
解决方法:

delete from Person where Id in (select Id from (select a.Id from Person a, Person b where a.Email=b.Email and  a.Id>b.Id) t)

原理是把第一遍的查询结果作为新表t在使用,规避了错误

ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable)

报错原因:mysql的设置默认是不允许创建函数
解决方法:
1,更改全局配置

  SET GLOBAL log_bin_trust_function_creators = 1;  

2、更改配置文件my.cnf

  log-bin-trust-function-creators=1   重启服务生效

你可能感兴趣的:(MySQL成长之路)