mysql基礎知識學習

來源:互聯網
上載者:User

標籤:mysql   sql   

 

1      說明

資料庫的命令時不區分大小寫,例如“CREATE DATABASE test”與“create database test”是同樣有效。

2      串連資料庫

1) 串連到本機上的MYSQL

串連資料庫可以用phpadmin管理平台,也可以用命令列方式,本次我使用的是wamp搭建的環境,wamp內建有mysql資料庫和工具,通過命令列對mysql進行操作。進入mysql資料庫的命令:mysql -u root –p

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/8B/55/wKioL1hKHKuC3LgaAAAySFc6h90661.png" title="1.png" alt="wKioL1hKHKuC3LgaAAAySFc6h90661.png" />

2) 串連到遠程主機上的MYSQL

假設遠程主機的IP為:1.1.1.1,使用者名稱為root,密碼為root。則鍵入以下命令:

    mysql –h 110.110.110.110-u root -p root

3      資料庫命令

1)建立資料庫test

Create database test

 

2)建立資料表persons

create tablepersons

(

firstnamevarchar(8),

lastnamevarchar(8),

age int

)

 

3)在資料表中插入一條新記錄

insert into persons(age,firstname,lastname) values (25,zhang,san)

 

4)查詢persons表中所有資料

select * from persons

 

5)條件查詢,從資料庫中查詢結果,查詢persons表中age欄位為25的資料。

select * from personswhere age=25

 

6)order by排序,按age欄位進行升序排序,order by預設是按升序排序,如果要按降序排列則在後門加上DESC。

select * from personsorder by age

 

7order by另類用法,如果order by後面接具體的數字,則表明按表格第幾列進行排序,例如order by 1則表明按表格的第一列進行排序,如果order by後面的數字大於表格的列數,則會報錯,這種用法通常用於SQL注入中判斷資料庫表的欄位數。

select * from personsorder by 1

 

8)修改表中資料:修改persons表中firstname欄位為xiao的age的值為100

update personsset age=100 where firstname=‘xiao‘

 

9刪掉資料庫中的資料:刪掉persons表中age為100的資料

delete from persons where age=100

 

10)刪除資料表,刪除persons資料表

drop tablepersons

 

11)刪除資料庫,輸出test1資料庫

drop tabletest1

 

12)查看資料庫

show databases

 

13)查看資料表

Show tables



14)查看資料表中有哪些欄位:查看users表中有哪些欄位

show columns from users

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M01/8B/5C/wKiom1hKW9mBNkCoAAAfHq51xH8460.png" title="1.png" alt="wKiom1hKW9mBNkCoAAAfHq51xH8460.png" />


mysql基礎知識學習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.