1.MySQL 數(shù)據(jù)庫連接
cmd 命令連接方法
1.首先使用 cd 切換 目錄至MySQL bin 目錄下
cd :D:\MySQL\bin
2.使用連接命令
mysql -hlocalhost -utest -p
3.輸入密碼連接成功
2.數(shù)據(jù)庫基本操作
顯示數(shù)據(jù)版本,需要加括號
select version();
顯示當(dāng)前時間,需要加括號
select now();
查看當(dāng)前數(shù)據(jù)庫,需要加括號
select database();
3.創(chuàng)建表的約束
-- int unsigned 無符號整形
-- auto_increment 表示自動增長
-- not null 表示不能為空
-- primary key 表示主鍵
-- default 默認(rèn)值
4.查看創(chuàng)建數(shù)據(jù)庫的語句
show create database 名稱?
5.查看表結(jié)構(gòu)
desc 數(shù)據(jù)表的名字;
6.enum
約束值
enum('男','女','中性')
7.修改表?
添加字段
alter table classes add chongwu varchar(20) default "一個美夢";
修改字段(修改類型,賦值等)
alter table classes modify chongwu varchar(20) default "一棟房子";
修改字段(重命名)
alter table classes change chongwu mascot varchar(20) default "一個美夢";
刪除字段
alter table classes drop mascot;
8.表插入數(shù)據(jù)
auto_increment 如果需要默認(rèn)自增,可以填0,null,default
9. 邏輯刪除
用一個字段來表示 這條信息是否已經(jīng)不能再使用了
給students表添加一個 is_delete 字段 bit 類型
alter table students add is_delete bit default 0;
update students set is_delete=1 where id=3;
10.select分組后面只有兩種字段
分組值,聚合函數(shù)
11.group_concat函數(shù),組合字段
12.isnull()函數(shù)
isnull(A,B)
如果A值為空,顯示B;
13.向mysql 數(shù)據(jù)庫中導(dǎo)入數(shù)據(jù);
創(chuàng)建表格:
導(dǎo)入數(shù)據(jù):
load data local infile ’D:/Download/suserinfo.csv‘ into table userinfo fields terminated by ',';(文件路徑,使用左斜杠,不能有中文)
load data local infile '(文件路徑,左斜杠)' into table orderinfo fields terminated by ',',
14.replace函數(shù)應(yīng)用
replace函數(shù)
replace('字段','a','b’)將a 變成b
update orderinfo set paidtime=replace(paidtime,'/','-') where paidtime is not null;
將paidtime中的’/'替換成‘-’;