目錄
一:數(shù)據(jù)庫的操作
1.顯示數(shù)據(jù)庫
2.創(chuàng)建數(shù)據(jù)庫
3.使用數(shù)據(jù)庫
4.刪除數(shù)據(jù)庫
二:常用數(shù)據(jù)類型
1.數(shù)值類型:整型和浮點(diǎn)型
2.字符串類型
3.日期類型
三:表的操作
1.查看表結(jié)構(gòu)
2.創(chuàng)建表
3.刪除表
一:數(shù)據(jù)庫的操作
1.顯示數(shù)據(jù)庫
語法:文章來源:http://www.zghlxwxcb.cn/news/detail-714494.html
show databases;?
2.創(chuàng)建數(shù)據(jù)庫
(1)簡化語法
create database?數(shù)據(jù)庫名;
(2)例子
-- 創(chuàng)建名為student的數(shù)據(jù)庫
create database student;
-- 如果系統(tǒng)沒有person數(shù)據(jù)庫,則創(chuàng)建
create database if not exists? person;
--如果系統(tǒng)沒有school數(shù)據(jù)庫,則創(chuàng)建一個使用utf8mb4字符集的school數(shù)據(jù)庫,如果有則不創(chuàng)建
create database? if not exists? school character? set utf8mb4;
(3)說明 :當(dāng)創(chuàng)建數(shù)據(jù)庫沒有指定字符集和校驗(yàn)規(guī)則時,系統(tǒng)默認(rèn)使用utf8,校驗(yàn)規(guī)則是:utf8_general_ci
3.使用數(shù)據(jù)庫
語法:
use? 數(shù)據(jù)庫名;
4.刪除數(shù)據(jù)庫
語法:刪除的是庫和庫里面的所有數(shù)據(jù)
drop? database 數(shù)據(jù)庫名;
二:常用數(shù)據(jù)類型
1.數(shù)值類型:整型和浮點(diǎn)型
數(shù)據(jù)類型 | 大小 | 說明 | 對應(yīng)Java類型 |
BIT[(M)] | M指點(diǎn)位數(shù),默認(rèn)為1 | 二進(jìn)制數(shù),M范圍從1到64,存儲數(shù)值范圍從0-2^M-1 | 常用boolean對應(yīng)BIT,此時 默認(rèn)位數(shù)是1位,及只能存0和1 |
TINYINT | 1字節(jié) | byte | |
SMALLINT | 2字節(jié) | short | |
INT | 4字節(jié) | integer | |
BIGINT | 8字節(jié) | long | |
FLOAT(M,D) | 4字節(jié) | 單精度,M指定長度,D表示小數(shù)點(diǎn)位數(shù)。會發(fā)生精度丟失 | float |
DOUBLE(M,D) | 8字節(jié) | double | |
DECIMAL(M,D) | M/D最大值+2 | 雙精度,M指定長度。D表示小數(shù)點(diǎn)位數(shù)。精確數(shù)值 | bigdecimal |
NUMERIC(M,D) | M/D最大值+2 | bigdecimal |
2.字符串類型
數(shù)據(jù)類型 | 說明 | 對應(yīng)Java類型 |
VARCHAR(SIZE) | 可變長度字符串 | String |
TEXT | 長文本數(shù)據(jù) | String |
MEDIUMTEXT | 中等長度文本數(shù)據(jù) | String |
BLOB | 二進(jìn)制形式的長文本數(shù)據(jù) | byte[] |
3.日期類型
數(shù)據(jù)類型 | 大小 | 對應(yīng)Java類型 | |
DATETIME | 8字節(jié) | java.util.Date、java.sql.Timestamp | |
TIMESTAMP | 4字節(jié) | java.util.Date、java.sql.Timestamp |
三:表的操作
需要操作數(shù)據(jù)庫中表的時候,需要先使用該數(shù)據(jù)庫
1.查看表結(jié)構(gòu)
語法:
desc 表名;
2.創(chuàng)建表
(1)語法
create table? 表名(字段名? 類型,字段名 類型……);
(2)可以使用comment增加字段說明
create? table? student (
????????id int ,
????????name varchar(20) comment '姓名',
????????password varchar(20) comment'密碼'
);
3.刪除表
語法:
drop table 表名;文章來源地址http://www.zghlxwxcb.cn/news/detail-714494.html
到了這里,關(guān)于【MySQL數(shù)據(jù)庫重點(diǎn)】第二節(jié):MySQL基礎(chǔ)知識(基本操作)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!