MySQL常用命令總結

來源:互聯網
上載者:User

標籤:唯一索引   插入   date   val   檔案名稱   log   表名   base   TE   

  MySQL資料庫對大小寫不敏感,如id和ID,select和SELECT.。

1.資料庫

  create database <資料庫名>  建立資料庫

  use <資料庫名>  串連資料庫

  註:use表示當前串連上了哪個資料庫,並不會影響對其他資料庫的訪問

          如: use db_1;

                  select * from db_2.logs

  drop database <資料庫名> 刪除資料庫,不會提箱

  drop database if exists <資料庫名> 如果存在,刪除資料庫

  show databases  查詢所有資料庫

  select version() 查詢資料庫版本

  select database() 查詢資料庫名稱

2.表

  show tables 查詢所有表

  create table <表名>( <欄位名1> <類型1>[,...<欄位名n> <類型n>] )   建立資料庫

  drop table  <表名>  刪除表

  drop table if exist  <表名>  如果存在,刪除表

  rename table <原表名> to <新表名>

  delete from <表名> where <運算式> 刪除表中資料

  insert into <表名> [(<欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )] 插入資料

  update <表名> set 欄位=值, ... where <運算式>  更新表中資料

  select <欄位1,欄位2, ...> from <表名> where <運算式> order by <欄位x, ...> limit m,n group by <欄位y, ...> having <運算式>  查詢

  alert table <表名> add <欄位名> <類型>[... 其他]  給表增加欄位

  alert table <表名> drop <欄位名>  刪除表中的欄位

  alert table <表名> change <原欄位名>   <新欄位名> <新的類型>  修改表中欄位

  alert table <表名> add index <索引名> (<欄位名1[, 欄位名2 ...]>) 給表添加索引

  alert table <表名> add unique <索引名> (<欄位名>) 給表添加唯一索引

  alert table <表名> add primary key (<欄位名>)   給表中的主鍵添加索引

3.備份

  mysqldump -u <使用者名稱> -p <資料庫名>  >  匯出的檔案名稱        匯出資料庫,匯出檔案預設在mysql/bin目錄下

  mysqldump -u <使用者名稱> -p <資料庫名>  <表名>   >  匯出的檔案名稱

 

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.