mysql伺服器常用命令和sql語句總結(1/5)

來源:互聯網
上載者:User

一、啟動與退出
1、進入MySQL:啟動MySQL Command Line Client(MySQL的DOS介面),直接輸入安裝時的密碼即可。此時的提示符是:mysql>
2、退出MySQL:quit或exit
二、庫操作
1、、建立資料庫
命令:create database <資料庫名>
例如:建立一個名為xhkdb的資料庫
mysql> create database xhkdb;
2、顯示所有的資料庫
命令:show databases (注意:最後有個s)
mysql> show databases;
3、刪除資料庫
命令:drop database <資料庫名>
例如:刪除名為 xhkdb的資料庫
mysql> drop database xhkdb;
4、串連資料庫
命令: use <資料庫名>
例如:如果xhkdb資料庫存在,嘗試存取它:
mysql> use xhkdb;
工具提示:Database changed
5、查看當前使用的資料庫
mysql> select database();

6、當前資料庫包含的表資訊:
mysql> show tables; (注意:最後有個s)

三、表操作,操作之前應串連某個資料庫
1、建表
命令:create table <表名> ( <欄位名1> <類型1> [,..<欄位名n> <類型n>]);

mysql> create table MyClass(
> id int(4) not null primary key auto_increment,
> name char(20) not null,
> sex int(4) not null default '0',
> degree double(16,2));
2、擷取表結構
命令: desc 表名,或者show columns from 表名
mysql>DESCRIBE MyClass
mysql> desc MyClass;
mysql> show columns from MyClass;
3、刪除表
命令:drop table <表名>
例如:刪除表名為 MyClass 的表
mysql> drop table MyClass;
4、插入資料
命令:insert into <表名> [( <欄位名1>[,..<欄位名n > ])] values ( 值1 )[, ( 值n )]
例如,往表 MyClass中插入二條記錄, 這二條記錄表示:編號為1的名為Tom的成績為96.45, 編號為2 的名為Joan 的成績為82.99,編號為3 的名為Wang 的成績為96.5.
mysql> insert into MyClass values(1,'Tom',96.45),(2,'Joan',82.99), (2,'Wang', 96.59);
5、查詢表中的資料
1)、查詢所有行
命令: select <欄位1,欄位2,...> from < 表名 > where < 運算式 >
例如:查看錶 MyClass 中所有資料
mysql> select * from MyClass;
2)、查詢前幾行資料
例如:查看錶 MyClass 中前2行資料
mysql> select * from MyClass order by id limit 0,2;

或者:

mysql> select * from MyClass limit 0,2;
6、刪除表中資料
命令:delete from 表名 where 運算式
例如:刪除表 MyClass中編號為1 的記錄
mysql> delete from MyClass where id=1;
7、修改表中資料:update 表名 set 欄位=新值,… where 條件
mysql> update MyClass set name='Mary' where id=1;
7、在表中增加欄位:

首頁 1 2 3 4 5 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.