一:mysql alter table的命令

1:增加字段

单个字段

ALTER TABLE `test` ADD  `msg_id` CHAR(32)   NOT NULL DEFAULT '' COMMENT '消息id' ;

多个字段

ALTER TABLE `test` ADD COLUMN (
        `msg_id` CHAR(32)  NOT NULL DEFAULT '' COMMENT '消息id',
        `msg_content` text  COMMENT '消息内容'
)
2:删除字段
ALTER TABLE `test` DROP `msg_id`,DROP `msg_content`;
3:修改字段
ALTER TABLE `test` modify COLUMN  `msg_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '消息id';

二:php脚本执行水平分表alter table

header("Content-type: text/html; charset=utf-8");

$config = [
	'host'=>'######',
	'user'=>'######',
	'password'=>'######',
	'dbname'=>'######',
];
$con = @mysqli_connect($config['host'], $config['user'], $config['password']);
if (!$con){
	exit("mysql connect error");
}

mysqli_select_db($con,$config['dbname']);

for($i=0; $i<30; $i++){
	$tableName = "test_".$i;
	$sql = "ALTER TABLE `".$tableName."` ADD  `msg_id` CHAR(32)   NOT NULL DEFAULT '' COMMENT '消息id' ;";
	
	//$sql = "ALTER TABLE `".$tableName."` DROP `msg_id`, DROP `msg_content`";
	mysqli_query($con,$sql);
}

mysqli_close($con);
exit("done");