Mysql資料庫部分命令

2021-09-29 06:10:23 字數 2530 閱讀 5676

mysql -u root -p 	//進入資料庫

show

databases

;// 檢視所有資料庫

create

database 資料庫名;

//新建資料庫

drop

database 資料庫名;

//刪除資料庫

use 資料庫名;

//選擇資料庫

show

tables

;//展示資料庫中的資料表

create

table 表名(..

....

);//建立資料庫中的資料表

建立表的示例:

create

table 表名(

id int

notnull

auto_increment

,//不為空,並且自增

name varchar(10

)not

null

,//不為空

primary

key(id)

);

insert

into 表名 (欄位1,欄位2...

)values

(資料1,資料2...

);insert

into 表名 (欄位2...

)values

(資料2...

);//如果欄位1是自增欄位

insert

into 表名 values

(資料1,資料2...

);//如果能保證欄位和資料順序一致

//返回乙個二維表

select

*from 表名;

//返回整個二維表

select

*from 表名 where aa=x;

//返回滿足要求的指定的行

select

*from 表名 where aa=x and bb=y;

// 返回滿足多個要求的指定的行

select aa,bb from 表名;

//返回指定的列

select

count(*

)from 表名;

//返回表裡面的資料條數,這個二維表(1*1)以count(*)命名

select

count(*

) number from 表名;

//返回表裡面的資料條數,這個二維表以number命名

select

count(*

) number from 表名 group

by aa;

//返回表裡面的資料條數,這個變數以number命名,並且以aa為尺度將這個變數劃分為若干條

select aa,

count(*

) number from 表名 group

by aa;

//只能是aa,不能是其他表項

select

*from 表名1,表名2

;//如果表1有m條記錄,表2有n條記錄,表1和表2有對應關聯鍵,那麼返回表有m*n條記錄

select

*from 表名1,表名2

inner

join

+ 條件;

//返回的值是int值,是符合條件的更新的記錄數目

update 表名 set aa=x;

//更新某些專案的數值

update 表名 set aa=x where bb=y;

//篩選符合條件的行

update 表名 set aa=x,cc=z where bb=y;

//更新多個數值

delete

from 表名;

//刪除整個表

delete

from 表名 where aa=x;

//刪除指定的行

delete

from 表名 where aa=x and bb=y;

//刪除有更多限制的指定的行

**太多,先放一張圖吧

幾點說明:

各**功能與jdbc查詢相似

其中,更新的結果是int

mysql 資料庫安裝命令 MySQL 資料庫安裝

4.安裝資料庫 scripts mysql install db user mysql datadir usr local mysql data 這時候報錯了,提示我們沒有找到.scripts mysql install db 這個裡這個檔案或者目錄 因為 mysql install db 這個檔案...

mysql資料庫打折命令 Mysql資料庫常用命令

1.建立資料庫 1 mysql create database test 在mysql裡面建立資料庫,資料庫的id是test。3 root host mysqladmin u root p create test 在linux下建立資料庫,資料庫的id是test。2.刪除資料庫 mysql drop...

mysql資料庫打折命令 mysql資料庫常用命令

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