ALTER TABLE tablename MODIFY[COLUMN] column_definition[FIRST|AFTER col_name]
EP:
alter table test modify name varchar(120);
2、增加表字段,语法如下:
ALTER TABLE tablename ADD [COLUMN] column_definition [FIRST|AFTER col_name]
EP:
alter table test add cloumn age int(3);
3、删除表字段、语法如下:
ALTER TABLE tablename DROP [COLUMN] col_name
EP:
alter table test dtop column age;
4、字段改名、语法如下:
ALTER TABLE tablename CHANGE [COLUMN] old_col_name column_definition [FIRST|AFTER col_name]
EP:
alter table test change age age2 int(4)
注意:change和modify都可以修改表的定义,不同的是change后面需要写两次列名,不方便。但是change的优点是可以修改列名称,modify则不能。
5、修改字段排列顺序
EP:
alter table test add birth date after name;
6、更改表名字,语法如下:
ALTER TABLE tablename RENAME [TO] new_tablename
EP:
alter table test rename test2;
7、赋予某个用户权限:
grant select,insert on test.*to 'seaeast'@'localhost' identified by '123456';
收回insert权限:
revoke insert on test.* from 'seaeast'@'localhost';