mysql Error1093错误

场景演示:
mysql> create table test(id int,name varchar(12),primary key(id));
Query OK, 0 rows affected (0.04 sec)
mysql> insert into test values(1,‘ttt‘);
Query OK, 1 row affected (0.00 sec)
mysql> insert into test values(2,‘ttt‘);
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql>  update test set name=‘aaaa‘ where id  in (select id from test);
ERROR 1093 (HY000): You can‘t specify target table ‘test‘ for update in FROM clause

官方说明:

Error: 1093 SQLSTATE: HY000 (ER_UPDATE_TABLE_USED)

Message: You can‘t specify target table ‘%s‘ for update in FROM clause

This error occurs for attempts to select from and modify the same table within a single statement. If the select attempt occurs within a derived table, you can avoid this error by setting the derived_merge flag of the optimizer_switch system variable to force the subquery to be materialized into a temporary table, which effectively causes it to be a different table from the one modified. See Section 9.2.2.3, “Optimizing Derived Tables and View References”.

mysql不支持,在一条语句对同一个表,先查询再更新的操作。

解决方法1:改成sql

比如:利用临时表

mysql>  update test set name=‘aaaa‘ where id  in (select id from (select id from test)c);
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2  Changed: 2  Warnings: 0

解决方法2:

官方说:可以通过设置optimizer_switch的 derived_merge参数来解决。

备注:Oracle是不会这个问题的

时间: 2024-08-06 21:22:18

mysql Error1093错误的相关文章

mysql链接错误:2003 can't connect to mysql server on 10038

出现这个错误原因是端口号不是3306. 打开D:\Program Files\MySQL\MySQL Server 5.5 \my.ini文件,当然还有其他的.ini的文件: [client] port=3306 [mysql] default-character-set=utf8 # SERVER SECTION# ----------------------------------------------------------------------## The following opt

解决Linux下MySQL启动错误Starting MySQL.Manager of pid-file quit without updating file.[FAILED]

刚装完MySQL,启动时报如下错误: Starting MySQL.Manager of pid-file quit without updating file.[FAILED] 依次尝试了从谷歌找到的各种方法,发现只要执行如下MySQL初始化命令即可解决: /usr/local/mysql/bin/mysql_install_db --user=mysql 下面附上从谷歌找到的解决此问题的方法集锦,也许每个人遇到的问题的原因会不一样,经供参考: 一.查看报错日志 报错日志是我们解决问题的方向灯

MAC中Django中runserver提示Can't connect to local MySQL server through socket '/tmp/mysql.sock错误

好像不止遇到一次,直接Google就可以了,在stackoverflow中就有答案,答案就是你没有开MySQL - -. stackoverflow链接见 http://stackoverflow.com/questions/16325607/cant-connect-to-local-mysql-server-through-socket-tmp-mysql-sock 开启MySQL的命令如下: mysql.server start MAC中Django中runserver提示Can't co

MySql 1045错误

配置时以管理员身份运行MySQL Instance Configuration Wizard 当你登录MySQL数据库出现:Error 1045错误时(如下图),就表明你输入的用户名或密码错误被拒绝访问了,最简单的解决方法就是将MySQL数据库卸载然后重装,但这样的缺点就是就以前的数据库中的信息将丢失,如果你不想重装,那么就需要找回密码或者重置密码.解决的方法应该有多种,这里我推荐大家使用一种原理通过,操作简单的方法,适用于windows以及linux平台. MySQL 1045错误如图: ER

mysql连接错误导致用户blocked

1.每过一段时间线上业务就会出现如下错误: kHost 'XXXXX' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'Connection closed by foreign host 2.需要使用mysqladmin flush-hosts解锁用户 3.查看错误日志 4.查看官方文档对max_connect_errors的解释如下     当某用户连续的错误连接达到max_c

mysql链接错误

Warning: mysqli_connect() [function.mysqli-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in xxx.php on line 14 解决方案: cd /var sudo mkdir mysql sudo chmod 755 mysql cd mysql ln -s /tmp/mysql.sock mysql.

MYSQL登录错误:mysqladmin: connect to server at ‘localhost’ failed

一.mysql登录错误 mysqladmin: connect to server at 'localhost' failed       error: 'Access denied for user 'root'@'localhost' (using password: YES)' 解决办法:破解mysql密码 #> service mysqld stop       #>mysqld_safe --skip-grant-tables &       输入 mysql -uroot

Mac启动mysql出现错误

Mac启动mysql出现错误error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' 刚刚升级mac到10.10,重新用Homebrew安装了出现提示: A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. To connect:

MySQL数据库错误server_errno=2013的解决

MySQL数据库错误server_errno=2013的解决 一组MySQL复制环境中的Master意外掉电,重启后Master运行正常,但该复制环境中的其它slave端,Error Log中却抛出的如下错误信息: Version: '5.6.17-log' socket: '' port: 3306 MySQL Community Server (GPL) 2014-09-26 18:30:19 5940 [Warning] Slave SQL: If a crash happens this