MYSQL資料庫------操作命令筆記

來源:互聯網
上載者:User

標籤:

一、資料庫連接

 

* 串連資料庫命令(前提需要安裝mysq ):

   mysql -h hostIp -u userName -pPassWord

 

二、資料庫操作

 

* 查看所有資料庫:

  show databases;

 

* 選中資料庫

   use databaseName ;

* 建立資料庫

  create database databaseName;

 

* 刪除資料庫

  drop databaseName;

  

 

三、表格操作

* 查看當前資料庫的表格

  show tables;

* 建立表格

  create table tableName  (   columnName1 type constraint,   columnName2 type constraint,  ..   unique(columnName)  )   資料類型:   integer(size) 整數,size規定了數值最大的位元;   decimal(size,d)容納帶有小數的數字;   numberic(size,d) size,數位最大位元,d小數右側的最大位元;   char(size) 固定長度的字串;   varchar(size) 容納可變長度的字串 size 字串的最大長度;  constraintsn約束:   not null  約束強制列不為null   unique 約束唯一標識資料庫表中的每條記錄 (ALTER TABLE tableName add UNIQUE(columnName))   primary key 主鍵,約束唯一標識資料庫表中的每條記錄,不可為空(null),每個表僅有一個唯一的主鍵;   foreign key 指向另一個表中的 primary key (ALTER TABLE tableName1  ADD FOREIGN (columnName) REFERENCES tableName2(columnName))   check 約束用於限制列中的值的範圍;   default 約束用於向列中插入預設的值 

四、資料操作(尋找、添加,刪除、更新)

* 查詢語句  select column_name from tbleName where columnName 運算子 value; * 運算子:=,<>,>,<,>=,<=,between,like; * 排序 order by (DESC,ASC)  select * from tableName order by columnName ASC; * 插入語句   insert into tableName  (columnName1,columnName2….) values (value1,value2…);  * 更新語句   update tableName  set columnName = newValue where columnName = value;  * 刪除語句  delete from tableName where columnName = value;

 -------暫時更新到這裡-------

隨便推薦一下:一個github上已經封裝好的php Mysql的類 點擊這裡查看

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.