mysql資料字典

2021-06-27 02:48:22 字數 2610 閱讀 9182

1、顯示資料庫列表2、顯示當前連線的資料庫

mysql>select database();

3、顯示庫中的資料表:

mysql>use mysql;(指定mysql庫)

mysql>show tables;

4、顯示資料表的結構:

mysql>describe yourtablename;

說明:describe 可以簡寫成desc

5、建庫:

mysql>create database yourdbname;

6、建表:

mysql>create table yourtablename (columnname colunmtype, ...);

6、刪庫和刪表:

mysql>drop database yourdbname;

mysql>drop table yourtablename;

7、退出

mysql>exit 

或mysql>quit

8、連線資料庫

mysql -h主機位址 -u使用者名稱 -p密碼

如:c:\users\administrator>mysql -hlocalhost -uroot -proot

welcome to the mysql monitor.  commands end with ; or \g.

your mysql connection id is 7

server version: 5.5.17 mysql community server (gpl)

oracle is a registered trademark of oracle corporation and/or its

affiliates. other names may be trademarks of their respective

owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql>

9、字段型別

1.int[(m)] 型: 正常大小整數型別

2.double[(m,d)] [zerofill] 型: 正常大小(雙精密)浮點數字型別

3.date 日期型別:支援的範圍是1000-01-01到9999-12-31。mysql以yyyy-mm-dd格式來顯示date值,但是允許你使用字串或數字把值賦給date列

4.char(m) 型:定長字串型別,當儲存時,總是是用空格填滿右邊到指定的長度

5.blob text型別,最大長度為65535(2^16-1)個字元。

6.varchar型:變長字串型別

10、啟用、禁用外來鍵約束

set foreign_key_checks='off';

set foreign_key_checks='on';

11、顯示建表sql

show create table 

12、顯示當前資料庫版本

select version();

13、顯示當前登入使用者

select user();

14、檢視指定表的索引資訊

show index from 表名稱

補充說明:mysql5中,關於索引的字典表是statistics,其中列collation表示索引的排序方式,值有2種,a表示公升序,null表示無分類。mysql5中,索引儲存的排序方式是asc的,沒有desc的索引。雖然索引是asc的,但是也可以反向進行檢索,就相當於desc了。如果您在order by 語句中使用了 desc排序,mysql確實會反向進行檢索。在理論上,反向檢索與正向檢索的速度一樣的快。但是在某些作業系統上面,並不支援反向的read-ahead預讀,所以反向檢索會略慢。由於設計的原因,在myisam引擎中,反向的檢索速度比正向檢索要慢得多。

其他

1、create table cc_weibo_bak (select * from cc_weibo)

2、insert into cc_weibo_bak(uid,content) select uid ,concat('hello1 ',nick_name) from uc_users;

3、select  fid  ,count(fid) as fans_count from uc_follow where fid in(select uid from uc_users where user_type=22) group by fid order by fans_count desc ;

4、show full processlist

5、show status

mysql 匯出資料字典

select table catalog,table schema as 資料庫名,table name as 表名,column name as 欄位名,ordinal position as 字段位置,column default as 字段預設值,is nullable 是否允許空值,data...

mysql維護資料字典

利用資料庫本身的備註字段 對錶和列增加備註字段。create table tb area area id int 2 not null auto increment comment 地點id area name varchar 200 default null comment 地點name prio...

mysql匯出資料字典彙總

select table catalog,table schema as 資料庫名,table name as 表名,column name as 欄位名,ordinal position as 字段位置,column default as 字段預設值,is nullable 是否允許空值,data...