mysql命令列命令1

2022-08-24 04:30:15 字數 2710 閱讀 3526

mysql的一些常用命令

開啟cmd命令視窗

mysql - 使用者名稱 -p (-h ip位址 -p埠號)

show databases 展示當前mysql中所包含的資料庫

create database 資料庫名 建立資料庫

use 資料庫名; 進入資料庫

create table 表名 ( 列名 資料型別()) 建立表

show tables 展示資料庫中包含的表

show columns from 表名 展示對應的表結構

describe 表名 展示對應的表結構

select 列名(,列名,列名....) form 表名 開啟對應列

select * from 表名 檢索表中全部的列

select distinct 列名 from 表名 只返回不同的值

select 列名 from 表名 limit 數字 表示返回不多於(數字)行

limit 數字,數字 第乙個數為開始位置,第二個為要檢索的行數

行0 檢索出來的第一行為行0

limit 4 offset 3 從行3開始取4行

select 表名.列名 from 資料庫名.表名 完全限定

select 列名 from 表名 order by 列名 對列以字母排序

select 列名1, 列名2,(....) from 表名 order by 列名1,列名3(...)

對多個列首先按列1排序 相同則再按照列3排序

select id,price,name from 表名 order by price desc 按照price降序排列(大的在前)

select id,price,name from 表名 order by price desc, name **降序後再對名字排序

多個列降序排列需對每個列指定

使用order by 和limit 可以檢索最高或者最低的值

例子select name,price from products where price=30(邏輯表示式)

(where應該位於order by 之前)

select name,price from products where price between 5 and 10

(between and 兩邊是閉合 包含5和10在內的所有數)

空值查詢

.........where 列名 is null

資料過濾

and 和 or

放在where語句後邏輯表達

and操作符優先順序更高,如果希望先執行or操作,可以使用圓括號

in操作符

select name,price from products where id in (11,12) order by name 檢索id為11 12的列

not操作符

select name,price from products where id not in (11,12) order by name 檢索除了id為 11,12的列

% 萬用字元

如 where name like 'jet%' 檢索全部以 jet開頭的詞

還可以 '%anvil%' 表示搜尋詞中包含anvil的詞

%可以代表 0 1 多個字元

_ 萬用字元

表示只匹配乙個字元

萬用字元效率非常低 不要過度使用

正規表示式是用來匹配文字的特殊的串

基本字元匹配

select name from products where name regexp '100' order by name

檢索 name列中 列值裡包含100的行 regexp 表示 其後跟著的是正規表示式

在表示式中 如 '.00' . 表示匹配任意乙個字元

like與regexp的區別

like 匹配的是列值整體,regexp匹配的是列值內的值

or 匹配

'100|200' 表示列值內含100或200

匹配幾個字元之一

'[ 123] ton' 等價於 '[1|2|3] ton' 意思是匹配 1 ton 或2 ton 或 3 ton

^ 否字元

' [^123] ' 表示匹配除這些字元以外的任何東西

- 匹配範圍

'[0-9]' 表示0到9 '[a-z]' 等

匹配特殊字元

在 ' ' 使用 \\ 作為前導 例如 '\\ .' 匹配乙個點 '\\-' 表示匹配乙個短橫槓

匹配字元類

匹配多個例項

以上為匹配乙個串中任意位置的文字

定位符為匹配特定位置的文字需使用定位符

Mysql命令列命令

第一招 mysql服務的啟動和停止 net stop mysql net start mysql 第二招 登陸mysql 語法如下 mysql u使用者名稱 p使用者密碼 鍵入命令mysql uroot p,回車後提示你輸入密碼,輸入12345,然後回車即可進入到mysql中了,mysql的提示符是...

mysql 命令列 回車 mysql命令列操作

顯示資料庫 show databases 當前資料庫 select database 顯示表show tables 更改表名稱 alter table 原表名 rename 新錶名 rename table 原表名 to 新錶名 檢視系統支援的引擎 show engines 檢視表的引擎 show ...

命令列 mysql 語句 MySQL命令列語句學習

1 mysql root 進入資料庫 2 help h 幫助 3 show databases 展示已經安裝的庫 4 create database 建立新的資料庫 5 drop database 刪除資料庫 6 use 使用資料庫 7 create table user id int,userna...