【MySQL學習筆記】

來源:互聯網
上載者:User

標籤:...   連接埠   插入資料   res   條件陳述式   cmd   date   mysql學習   開啟   

1.啟動與停止MySQL服務,在cmd中輸入:

net start  (名稱)  #啟動服務net stop  (名稱)  #停止服務

2.登入MySQL,在cmd中輸入:

mysql -u(使用者名稱) -p(密碼) -P(連接埠號碼) -h(地址)  #如果要退出MySQL,則輸入quit

3.建立資料庫:

creste database 資料庫名稱 character set=編碼方式;

4.查看資料庫列表:

show databases;

5.修改資料庫編碼方式:

alter database 資料庫名 character set=編碼方式;

7.刪除資料庫:

drop database 資料庫名;

8.開啟資料庫:

use 資料庫名;

9.建立資料表:

create table 表名(列名 約束,列名 約束,......);

10.查看資料表:

show tables;

11.查看資料表的結構:

show columns from 表名;

12.向資料表中摻入資料:

insert into 表名(列名,列名....) values(值1,值2.....) #列名稱可以沒有

13.資料表添加單列:

alter table 表名 add 列名 該列的約束條件或位置;

14.資料表刪除列:

alter table 表名 drop 列名;

15.資料表添加主鍵約束:

alter table 表名 add primary key (添加主鍵的列名);

16.資料表添加唯一約束:

alter table 表名 add unique (列名);

17.資料表添加外鍵約束:

alter table 表名 add foreigh key (列名);

18.資料表刪除主鍵約束:

alter table 表名 drop primary key;

19.資料表修改列定義:

alter table 表名 modify 列名 列定義 位置;  #位置可加可不加

20.資料表修改列名稱:

alter table 表名 change 舊列名 新列名 列定義 列位置;

21.資料表名稱修改;

alter table 表名 remane 新表名;

22.資料表插入資料:

insert 表名 set 列名=值;

23.更新資料表記錄:

update 表名 set 列名=值;  # 後面可以跟where字句

24.刪除資料表記錄:

delete from 表名 條件陳述式;

25.對查詢的結果進行分組:

group by 列名稱 (升序/降序);

26.對查詢結果的分組設定分組條件:

group by 列名 having 條件;

27.對查詢的結果進行排序:

...order by 列名 asc/desc;

28.限制查詢結果返回的數量:

...limit  數量或位置等;

【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.