連接認(rèn)證

-- 連接認(rèn)證

mysql.exe -h localhost -P 3306 -u root -p

--? 查看所有數(shù)據(jù)庫

show databases;

--? 斷開連接

exit

quit

\q

--? 雙中劃線+空格:注釋(單行注釋),也可以使用#號(hào)

--? 創(chuàng)建數(shù)據(jù)庫

create database medb charset utf8;

-- 創(chuàng)建關(guān)鍵字?jǐn)?shù)據(jù)庫

create database database charset utf8; --? 報(bào)錯(cuò)

--? 使用反引號(hào)

create database 'database' charset utf8;

--? 創(chuàng)建中文數(shù)據(jù)庫

create database 北京 charset utf8;

--? 如果報(bào)錯(cuò)解決方案:告訴服務(wù)器當(dāng)前中文的字符集是什么

set names gbk;

create database 北京 charset utf8;

--? 查看所有數(shù)據(jù)庫

show databases;

--? 創(chuàng)建數(shù)據(jù)庫

create database informationtest charset utf8;

--? 查看以information_開始的數(shù)據(jù)庫(_需要被轉(zhuǎn)義)

show databases like 'information_%'; --? 相當(dāng)于information%

show databases like 'information\_%';

-- 查看數(shù)據(jù)庫的創(chuàng)建語句

show create database mydb;

show create database 'database'; --? 關(guān)鍵字需要使用反引號(hào)

--? 修改數(shù)據(jù)庫informationtest的字符集

alter database informationtest charset GBK;

-- 刪除數(shù)據(jù)庫

drop database informationtest;

-- 創(chuàng)建表

create table if ont exists mydb.student( --

顯示地將student表放到mydb數(shù)據(jù)庫下

name varchar(10),

gender varchar(10),

number varchar(10),

age int

)charset utf8;

--? 創(chuàng)建數(shù)據(jù)庫表

--? 進(jìn)入數(shù)據(jù)庫

use mydb;

--? 創(chuàng)建表

create table class(

name varchar(10),

room varchar(10)

)charset utf8;

--? 查看所有表

show tables;

--? 查看以s結(jié)尾的表

show tables like '%s';

--? 查看表的創(chuàng)建語句

show create table student;

show create table student\g -- \g等價(jià)于

show create table student\G -- 將查到的結(jié)構(gòu)旋轉(zhuǎn)90度變成縱向

--? 查看表結(jié)構(gòu)

desc class;

describe class;

show columns from class;

--? 重命名表:student表->my_student

rename table student to my_student;

-- 修改表選項(xiàng):字符集

alter table my_student charset = GBK;

--? 給學(xué)生表增加ID,放到第一個(gè)位置

alter table my_student

add column id int

first;

--? 講學(xué)生表中的number學(xué)號(hào)字段變成固定長度,并且放到第二位(id之后)

alter table my_student modify number char(10) after id;

--? 修改學(xué)生表中的gender字段為sex

alter table my_student change gender sex varchar(10);

--? 刪除學(xué)生表中的age年齡字段

alter table my_student drop age;

--? 刪除數(shù)據(jù)表

drop table class;

--? 插入數(shù)據(jù)

insert into my_student

values(1,'ba20200001','Jim','male'),

(2,'ba20200002','Lily','female');

--? 插入數(shù)據(jù):指定字段列表

insert into my_student(number,sex,name,id) values

('bc20200003','male','Tom',3),

('bc20200004','female','Lucy',4);

--? 查看所有數(shù)據(jù)select * from my_student;

--? 查看指定字段,指定條件的數(shù)據(jù)

select id,number,sex,name from my_student

where id=1;? --? 查看滿足id為1的學(xué)生的信息

--? 更新數(shù)據(jù)

update my_student set sex='female' where name='Jim';

--? 刪除數(shù)據(jù)

delete from my_student where sex='male;

--? 創(chuàng)建整型表

create table my_int(

int_1 tinyint,

int_2 smallint,

int_3 int,

int_4 bigint

)charset utf8;

--? 插入數(shù)據(jù)

insert into my_int

values(100,100,100,100);? --? 有效數(shù)據(jù)

insert into my_int

values('a','b','199','f');? --? 無效數(shù)據(jù):類型限定

insert into my_int

values(255,10000,100000,1000000);? --? 錯(cuò)誤:超出范圍

--? 給表增加一個(gè)無符號(hào)類型

alter table my_int add int_5 tinyint unsigned;? --? 無符號(hào)類型

--? 插入數(shù)據(jù)

insert into my_int

values(127,10000,100000,1000000,255);

--? 指定顯示寬度為1

alter table my_int add int_6 tinyint(1) unsigned;

--? 插入數(shù)據(jù)

insert into my_int

values(127,0,0,0,255,255);

--? 顯示寬度為2,0填充

alter table my_int add int_7 tinyint(2) zerofill;

--? 插入數(shù)據(jù)

insert into my_int

values(1,1,1,1,1,1,1);

insert into my_int

values(100,100,100,100,100,100,100);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容