MySQL操作手冊

來源:互聯網
上載者:User

標籤:mysql資料庫操作

MySQL資料庫基本操作

一、概述:

    我們學習了如何安裝一個MySQL資料庫以後,我們就要學習如何操作MySQL資料庫,本文只是一些基本的操作sql語句,僅供參考。如有什麼不對的地方可以留言。謝謝!


二、具體操作:


    1、使用“su”命令進入到root使用者。


    2、直接輸入“mysql -u root -p”再次輸入密碼即可進入MySQL資料庫。

   3、建立資料庫。《create database 資料庫名;》
   4、查看資料庫。《show databases;》  查看錶結構《show tables;》
   5、開啟指定的資料庫。《use 資料庫名;》
   6、刪除資料庫。《drop database 資料庫名;》
   7、建立表。《create table 表名 (                 列名 資料類型 屬性/約束;                 .......                 .....               ) ;》
   8、主鍵。《primary key 定義主鍵》
   9、查看錶。《show tables;》
   10、查看錶結構。《先到‘use 資料庫;’後,使用‘describe 表名;’》
   11、修改表結構。《alter table 表名               add 列定義    //添加列              |drop 列名    //刪除列              |add index 索引名 (列名) //添加索引              |drop index 索引名 //刪除索引              |modify 列定義 //修改列的定義              |add primary key (列名) //添加主鍵              |drop primary key //刪除主鍵              |rename 新表名 //修改表名稱》
   12、插入資料。《insert into 表名[(列名,...n)] values (值,...)》
   13、查看錶中資料。《select 列名 [as 別名] [,...n]|*|運算式              ->from 表名[,...n]             ->[where 條件運算式]             ->[order by 列名]             ->[group by 列名]             ->[having 條件運算式]》
   14、刪除表中資料。《delete from 表名 [where 條件運算式];》
   15、修改表中資料。《update 表名 set 列名=值 [where 條件運算式];》
   16、刪除表。《drop table 表名;》


本文出自 “孤獨一夜” 部落格,謝絕轉載!

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.