mysql如何对先有表进行分区?
有一张表,已经创建了,是一张普通的表,先要对这张表进行hash分区,我用一下语句创建提示错误:
mysql> alter table 33
-> partition by hash(id)
-> partitions 2;
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 '33
partition by hash(id)
partitions 2' at line 1
难道对普通标不能进行分区,必须要在创建表的时候指定分区类型?
[解决办法]
你的表名是什么? 如果是33则需要加上 `33` 反引号(注意不是单引号)
mysql> create table x ( -> id int primary key, -> c int -> ) engine=myisam;Query OK, 0 rows affected (0.10 sec)mysql> alter table x -> PARTITION BY HASH(id) -> PARTITIONS 2;Query OK, 0 rows affected (0.15 sec)Records: 0 Duplicates: 0 Warnings: 0mysql>
[解决办法]
33为表名加引号。
alter table tb
partition by hash(id)
partitions 2;
[解决办法]
33表名加''
alter table tb
partition by hash(id)
partitions 2;