create table cyan ->( ->學(xué)號(hào) i" />
1、創(chuàng)建數(shù)據(jù)庫(kù):create database Thinkgamer;
2、刪除數(shù)據(jù)庫(kù):drop database Thinkgamer;
3、選擇使用某個(gè)數(shù)據(jù)庫(kù):use Thinkgamer;
4、創(chuàng)建數(shù)據(jù)表:
mysql>create table cyan
->(
->學(xué)號(hào) int(3) not null primary key,
->姓名 char(3);
->性別 char(1) not null default 1
->)engine = innodb;
回車即可,not null 設(shè)置該字段不能為空,primary key是設(shè)置主鍵,default 默認(rèn)名字為1。
5、刪除表:drop table cyan;
6、往表中添加列:alter table cyan add 愛(ài)好 char(20);
7、顯示該表的相關(guān)信息:describe cyan;
8、顯示某列信息:select 學(xué)號(hào) from cyan;
9、往表里添加信息:insert cyan values("111","Thinkgamer","女","舞蹈");
10、修改一個(gè)表某行信息:
mysql>update cyan
->set 性別=" 男”,愛(ài)好="羽毛球"
->where 學(xué)號(hào)=111;
回車即可。
1、修改多個(gè)表的某個(gè)信息:
mysql>update table_name1,table_name2
->set table_name1.性別=" 男”,table_name2.性別="女"
->where table_name1.id = table_name2.id;
回車即可。
12、刪除某行:delete from cyan where 學(xué)號(hào)=111;
13、刪除性別為女的人:delete from cyan where 性別=女;
14、刪除多表中的多行:
mysql>delete table1,table2
->from table1,table2,table3
->where table1.id=table2.id and table2.id=table3.id;
回車即可。
15、清除表中數(shù)據(jù):truncate table cyan;
注意:數(shù)據(jù)一旦清除,不可恢復(fù)。
其他:
select user(); 顯示當(dāng)前用戶。
select @@version; 顯示數(shù)據(jù)庫(kù)版本。
show cyan status; 顯示當(dāng)前所用表的狀態(tài)
show character set; 顯示數(shù)據(jù)庫(kù)支持的字符集
show variables like '%char%' 查看默認(rèn)字符集
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com