这里记录mysql、sqlServer脚本执行遇到的各种问题,方便追溯
解决:Statement violates GTID consistency: CREATE TABLE … SELECT. 0.000 sec
1、情况描述
在执行sql:create table 表A as select * from 表B
时,发现sql执行后,并未生成新的表,而是提示Statement violates GTID consistency: CREATE TABLE … SELECT.
2、问题分析
MySQL5.6及以上的版本,开启了 enforce_gtid_consistency=true 功能导致的,MySQL官方解释说当启用 enforce_gtid_consistency 功能的时候,MySQL只允许能够保障事务安全,并且能够被日志记录的SQL语句被执行,像create table … select 和 create temporarytable语句,以及同时更新事务表和非事务表的SQL语句或事务都不允许执行。
3、解决方法
方法一(推荐):
执行命令 :SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY = off;
或在配置文件中 :ENFORCE_GTID_CONSISTENCY = off;
方法二:
create table 表A as select 表B 的方式会拆分成两部分:
create table 表A like 表B ;
insert into 表A select *from 表B ;
解决:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column.
1、情况描述
在workbench执行delete from table where ...
的脚本时,报错: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. 0.047 sec
2、原因
在mysql的safe-updates模式中,如果where后跟的条件不是主键,就会出现这种错误。
3、解决方案
方法一(推荐):
执行命令:SET SQL_SAFE_UPDATES = 0;
然后在重新执行一遍你要删除的内容。
方法二:
调整sql,where条件中加入主键