多行命令輸入:注意不能將單詞斷開;當插入或更改資料時,不能將欄位的字串展開到多行裡,否則硬斷行符號將被儲存到資料中;
增加一個系統管理員帳戶:grant all on *.* to user@localhost identified by "password";
每條語句輸入完畢後要在末尾填加分號';',或者填加'\g'也可以;
查詢時間:select now();
查詢目前使用者:select user();
查詢資料庫版本:select version();
查詢當前使用的資料庫:select database();
4、建立表是先判斷表是否存在
create table if not exists students(……);
5、從已經有的表中複製表的結構
create table table2 select * from table1 where 1<>1;
6、複製表
create table table2 select * from table1;
7、對錶重新命名
alter table table1 rename as table2;
8、修改列的類型
alter table table1 modify id int unsigned;//修改列id的類型為int unsigned
alter table table1 change id sid int unsigned;//修改列id的名字為sid,而且把屬性修改為int unsigned
9、建立索引
alter table table1 add index ind_id (id);
create index ind_id on table1 (id);
create unique index ind_id on table1 (id);//建立唯一性索引
10、刪除索引
drop index idx_id on table1;
alter table table1 drop index ind_id;
11、聯合字元或者多個列(將列id與":"和列name和"="串連)
select concat(id,':',name,'=') from students;
12、limit(選出10到20條)<第一個記錄集的編號是0>
select * from students order by id limit 9,10;
select * from students procedure analyse();
select * from students procedure analyse(16,256);
第二條語句要求procedure analyse()不要建議含有多於16個值,或者含有多於256位元組的enum類型,如果沒有限制,輸出可能會很長;