MySQL 常用命令集合
1. 用户相关
创建一个本地用户,密码为 pwd
CREATE USER username@localhost IDENTIFIED BY ‘pwd';
给用户是授权, 可以授权具体的操作、或者所有权限,以及对应的密码
GRANT SELECT,INSERT,UPDATE,DELETE ON . to user@”%” IDENTIFIED BY “pwd”;
GRANT ALL PRIVILEGES ON u_database.* TO user@localhost;
删除一个用户
DELTE FROM user WHERE user=’username’ AND host=’localhost';
2. 表相关
增加列
ALTER TABLE table_name ADD column_name INT NOT NULL DEFAULT ‘0’ COMMENT ‘注释说明’
删除列
ALTER TABLE table_name DROP column_name
修改列的类型信息(或重命名)
#如只修改列类型,new_column_name可以和旧的列名称column_name相同
ALTER TABLE table_name CHANGE column_name new_column_name BIGINT NOT NULL COMMENT ‘注释说明’
增加主键
ALTER TABLE table_name ADD CONSTRAINT PK_SJ_RESOURCE_CHARGES PRIMARY KEY (column_key_name1, column_key_name2)
删除主键
ALTER TABLE table_name DROP PRIMARY KEY
重命名表
ALTER TABLE table_name RENAME new_table_name
创建索引
ALTER TABLE table_name ADD INDEX index_name (field_name);
删除索引
ALTER TABLE table_name DROP INDEX index_name;