MySQL資料庫簡單操作

2021-10-01 07:39:07 字數 2283 閱讀 7152

1.c:\users\administrator>mysql -u root -p//客戶端連線資料庫伺服器

enter password://有密碼輸入密碼登入,沒有直接回車進入

2.mysql> show databases;//顯示資料庫

3.mysql> drop database if exists class_13_db1//刪除資料庫

4.mysql> create database mydatabase;//建立資料庫

5.mysql> use mydatabase;//使用資料庫

6.mysql> create table student(

-> name varchar(20),

-> *** varchar(4),

-> id int(20),

-> chinses int(4),

-> math int(4),

-> english int(4)

-> );//建立表

7.mysql> show tables;顯示當前資料庫中有哪些表

8.mysql> insert into student (name,***,id,chinses,math,english) values

-> (『孫加成』,『男』,0201,85,78,99),

-> (『孫建明』,『男』,0202,78,88,86),

-> (『馬浩東』,『男』,0203,66,78,68),

-> (『李佳琪』,『女』,0204,99,78,92);//多行插入資料

9.mysql> insert into student values (『孫浩』,『男』,0205,65,45,52);//單行插入資料

10.mysql> select * from student;//全列查詢

11.mysql> select name,id from student;//指定列查詢

12.mysql> select name,chinses+math+english from student;//查詢欄位為表示式

13.mysql> select name,chinses+math+english 總分 from student;//起別名,這裡總分就是表示式chinses+math+english的別名

14.mysql> select distinct math from student;//去重

15.mysql> select name,chinses,id from student order by id;//排序,預設為從小到大排序

16.mysql> select name,chinses,id from student order by id desc;//從大到小排序

17.mysql> select name,chinses+math+english total from student order by total desc;

±----------±------+

| name | total |

±----------±------+

| 李佳琪 | 269 |

| 孫加成 | 262 |

| 孫建明 | 252 |

| 馬浩東 | 212 |

| 孫浩 | 162 |

±----------±------+

5 rows in set (0.00 sec)

18.mysql> select name from student where math<80;//條件查詢,可以使用表示式但不能使用別名!

mysql> select name from student where (chinses>90 or math<80)&&english >80;

mysql> select name from student where math between 70 and 80;

19.mysql> select name from student where name like 『孫%』;//模糊查詢

mysql> select name from student where name like 『孫_』;

±-------+

| name |

±-------+

| 孫浩 |

±-------+

1 row in set (0.00 sec)

20.mysql> update student set math=math+10 where name=『孫建明』;//修改資料

21.mysql> delete from student where name=『孫建明』;//刪除資料

Mysql資料庫簡單操作

net start mysql 服務名 l l net stop mysql 服務名停止 bin mysqladmin uroot shutdown l 登陸資料庫 開啟dos 視窗 l mysql u root p mysql lmysql uroot p p5188 db1 default ch...

MySQL資料庫簡單操作

建立資料庫,同時設定字符集和校驗規則 create database ifnot exists testdb default character set utf8 collate utf8 general ci 刪除資料庫,不存在會報錯 drop database testdb 顯示所有資料庫 sh...

簡單mysql資料庫操作

建立資料庫鏈結,mysql connect localhost mysql user mysql password or die could not connect mysql error 選擇資料庫 mysql select db mydb 設定字符集 mysql query set names ...