mysql> create table lzldb.tab1 as select * from mysql.user limit 1;
ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
mysql 开启GTID功能,有一些限制,create table as语句不可用使用...
网上搜了下支撑create table xxx like xx
试下该语法,可以使用
mysql> create table lzldb.user like mysql.user;
Query OK, 0 rows affected (0.03 sec)
加个limit,不行
mysql> create table lzldb.user like mysql.user limit 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 1' at line 1
如果想用limit,可以获取ddl语句,然后insert
show create table mysql.user;
把表名改下,然后用ddl创建新表
use lzldb;
CREATE TABLE `tab3` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(32) COLLATE utf8_bin NOT NULL DEFAULT '',
...
`Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',
-> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges'
-> ;
Query OK, 0 rows affected (0.02 sec)
用select * from插入数据
mysql> insert into tab3 select * from mysql.user limit 1;
Query OK, 1 row affected (0.01 sec)
Records: 1 Duplicates: 0 Warnings: 0
ok,实现create table as select limit的功能