用戶權限類
授予權限
GRANT privileges ON databasename.tablename TO 'username'@'host';
privileges:用戶的操作權限,如SELECT
, INSERT
, UPDATE
等.如果要授予所的權限則使用ALL
databasename:數(shù)據(jù)庫名
tablename:表名,如果要授予該用戶對所有數(shù)據(jù)庫和表的相應操作權限則可用表示, 如.*
注意:用以上命令授權的用戶不能給其它用戶授權,如果想讓該用戶可以授權,用以下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
撤銷權限
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
查看授予的權限
show grants for root@'localhost';
刪除用戶
DELETE FROM user Where User='test' AND Host='localhost';
表結構變更類
更改表名
alter table tablename rename tablenewname;
更改字段類型
alter table tablename modify column columnname typename;
更改字段默認值
alter table tablename alter column columnname set default '';
添加字段
alter table tablename add columnname varchar(10) not Null;
查看和更改自增字段的值
select auto_increment from information_schema.tables where table_schema='db name' and table_name='table name';
alter table tablename auto_increment=NUMBER;;
數(shù)據(jù)存取類
從數(shù)據(jù)庫里隨機讀取幾條數(shù)據(jù)
SELECT * FROM table order by rand() limit 20;
數(shù)據(jù)庫編碼類
創(chuàng)建UTF-8數(shù)據(jù)庫
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;