Linux下mysql的常用操作

來源:互聯網
上載者:User

標籤:tables   style   http   dump   describe   str   databases   arch   int   

Linux下mysql的常用操作:

  1. 顯示資料庫  
    show databases;
  2. 選擇資料庫
    use 資料庫名;
  3. 顯示資料庫中的表
    show tables;
  4. 顯示資料表的結構
    describe 表名;
  5. 顯示表中的記錄
    SELECT * FROM 表名
  6. 建庫
    create databse 庫名;
  7. 建表
    create table 表名 (欄位設定列表);mysql> create table name(    -> id int auto_increment not null primary key ,    -> uname char(8),    -> gender char(2),    -> birthday date );Query OK, 0 rows affected (0.03 sec)mysql> show tables;+------------------+| Tables_in_userdb |+------------------+| name             |+------------------+1 row in set (0.00 sec)mysql> describe name;+----------+---------+------+-----+---------+----------------+| Field    | Type    | Null | Key | Default | Extra          |+----------+---------+------+-----+---------+----------------+| id       | int(11) | NO   | PRI | NULL    | auto_increment || uname    | char(8) | YES  |     | NULL    |                || gender   | char(2) | YES  |     | NULL    |                || birthday | date    | YES  |     | NULL    |                |+----------+---------+------+-----+---------+----------------+4 rows in set (0.00 sec)註: auto_increment 自增     primary key    主鍵
  8. 增加記錄
     insert into name(uname,gender,birthday) values(‘張三‘,‘男‘,‘1971-10-01‘);
  9. 修改記錄
    update name set birthday=‘1971-01-10‘ where uname=‘張三‘;
  10. 刪除記錄
    delete from name where uname=‘張三‘;
  11. 刪除表
    drop table 表名
  12. 刪除庫
     drop database 庫名;

     

  13. 備份資料庫
    mysqldump -u root -p --opt 資料庫名>備份名; //進入到庫目錄

     

  14. 恢複
    mysql -u root -p 資料庫名<備份名; //恢複時資料庫必須存在,可以為空白資料庫

     

原文:  http://www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html

Linux下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.