MySQL得基本操作

2021-10-10 07:04:11 字數 3500 閱讀 2436

mysql資料庫:

windows安裝mysql

直接執行安裝檔案安裝

啟動和連線mysql服務

連線資料庫

mysql資料庫結構

資料元素 --> 記錄 -->資料表 --> 資料庫

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-ej0aqrp1-1604580332668)(img/kujiegou.png)]

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-cfewbxod-1604580332671)(img/biaojiegou.png)]

sql語言:

結構化查詢語言(structured query language),一種特殊目的的程式語言,是一種資料庫查詢和程式語言,用於訪問資料以及查詢、更新和管理關係資料庫系統。

資料庫管理:

檢視已有庫

show databases;

建立庫

create database 庫名 [character set utf8];

e.g. 建立stu資料庫,編碼為utf8

create database stu character set utf8;

create database stu charset=utf8;

注意:庫名的命名

數字、字母、下劃線,但不能使用純數字

庫名區分字母大小寫

不要使用特殊字元和mysql關鍵字

切換庫

use 庫名;

e.g. 使用stu資料庫

use stu;

檢視當前所在庫

select database();

刪除庫

drop database 庫名;

e.g. 刪除test資料庫

drop database test;

資料表管理:

基本思考過程

確定儲存內容

明確字段構成

確定字段資料型別

基礎資料型別

表得基本操作:

create table 表名(欄位名 資料型別 約束,欄位名 資料型別 約束,…欄位名 資料型別 約束);

e.g.  建立班級表

create table class_1 (id int primary key auto_increment,name varchar(32) not null,age tinyint unsigned not null,*** enum('w','m'),score float default 0.0);

e.g. 建立興趣班表

create table interest (id int primary key auto_increment,name varchar(32) not null,hobby set('sing','dance','draw'),level char not null,price decimal(6,2),remark text);

表資料得基本操作:

3.5.1 插入(insert)

insert into 表名 values(值1),(值2),...;

insert into 表名(欄位1,...) values(值1),...;

e.g.

insert into class_1 values (2,'baron',10,'m',91),(3,'jame',9,'m',90);

insert into class_1 (name,age,***,score) values ('lucy',17,'w',81);

3.6.2 查詢(select)
select * from 表名 [where 條件];

select 欄位1,欄位2 from 表名 [where 條件];

e.g.

select * from class_1;

select name,age from class_1;

3.6.3 where子句

where子句在sql語句中扮演了重要角色,主要通過一定的運算條件進行資料的篩選,在查詢,刪除,修改中都有使用。

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-h0nzt0o8-1604580332673)(img/suanshu.png)]

e.g.

select * from class_1 where age % 2 = 0;

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-gqhtm4iv-1604580332675)(img/bijiao.png)]

e.g.

select * from class_1 where age > 8;

select * from class_1 where between 8 and 10;

select * from class_1 where age in (8,9);

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-0qvp4iu4-1604580332677)(img/luoji.png)]

e.g.

select * from class_1 where ***='m' and age>9;

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳(img-mythbjpn-1604580332679)(img/yunsuanfu.png)]

查詢練習

1. 查詢30多元的圖書

2.查詢人民教育出版社出版的圖書 

3.查詢老舍寫的,中國文學出版社出版的圖書 

4.查詢備註不為空的圖書

5.查詢**超過60元的圖書,只看書名和**

6.查詢魯迅寫的或者茅盾寫的圖書

0332677)]

e.g.

select * from class_1 where ***=『m』 and age>9;

[外鏈轉存中...(img-mythbjpn-1604580332679)]
查詢練習

查詢30多元的圖書

2.查詢人民教育出版社出版的圖書 

3.查詢老舍寫的,中國文學出版社出版的圖書 

4.查詢備註不為空的圖書

5.查詢**超過60元的圖書,只看書名和**

6.查詢魯迅寫的或者茅盾寫的圖書

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...

mysql基本操作

1,檢視資料庫狀態 及啟動停止 etc init.d mysqld status etc init.d mysqld start etc init.d mysqld stop 2,給使用者配置初始密碼123456 mysqladmin u root password 123456 3,修改root使...