1. 程式人生 > >mysql簡單的查詢語句(一)

mysql簡單的查詢語句(一)

1、 查詢資料庫的版本 : mysql –-version 或者為 –V
2、 啟動服務: net start mysql
3、 關閉服務: net stop mysql
4、 連線資料庫:mysql –h(localhost或ip) –P(埠預設為3306) –uroot –p(密碼)
可以省略密碼 等下輸
5、 查詢當前資料庫 show databases;(查詢所有資料庫) 也可 show databases like’’;
查詢相對應的資料庫
6、 建立資料庫 create database 資料庫名 charset=字符集
7、 檢視資料的建立資訊:show create database 資料名
8、 更改資料庫的字符集 alter database 資料庫名 charset=字符集
9、 檢視當前所使用的資料庫: select database()
10、 在登入了資料的情況下檢視資料庫的版本 select version();
11、 建立表 create table 資料名.表名 (欄位名 欄位屬性 ,欄位名 欄位屬性,。。。)charset=字符集 如果建立的表所屬的資料庫為當前正在使用的資料庫可以省略 資料名.
12、 檢視資料的建立資訊 show create 資料庫名.table 表名;同上也可以省略
13、 修改表的字符集 alter table 表名 charset=字符集;
14、 修改表的名字: rename table 表名to 新的表名
15、 檢視別的資料庫的表: show tables from 資料庫名
16、 刪除單個表: drop table 表名;
17、 刪除多個表: drop table 表名1,表名2.。。。。。;
18、 查看錶的各個欄位的屬性和鍵 desc 表名;或者 show columns from 表名。
19、 向表中新增屬性: alter table 表名add 欄位名 欄位屬性 位置 ;
20、 從表中刪除屬性: alter table 表名drop 欄位名;
21、 修改表中欄位的名字:alter table change 舊欄位名字 新欄位名字 新欄位屬性
22、 修改表中欄位的屬性 alter table modify 舊欄位的名 新的屬性。
23、 向表中插入資料 insert into 表名(屬性1,屬性2,。。。)values(值1,值2,。。。)
24、 修改表裡的資料 update 表名 set 欄位名=value where 條件。