linux系統(tǒng)進入mysql數(shù)據(jù)庫的方法:
專注于為中小企業(yè)提供網(wǎng)站制作、做網(wǎng)站服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)都蘭免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
連接MYSQL:
格式: mysql -h主機地址 -u用戶名 -p用戶密碼
1、連接到本機上的MYSQL。
首先在打開DOS窗口,然后進入目錄 mysqlbin,再鍵入命令mysql -uroot -p,回車后提示你輸密碼,如果剛安裝好MYSQL,超級用戶root是沒有密碼的,故直接回車即可進入到MYSQL中了,MYSQL的提示符是:mysql
2、連接到遠程主機上的MYSQL。假設(shè)遠程主機的IP為:110.110.110.110,用戶名為root,密碼為abcd123。則鍵入以下命令:
mysql -h110.110.110.110 -uroot -pabcd123(注:u與root可以不用加空格,其它也一樣)
3、退出MYSQL命令: exit (回車)
一個建庫和建表以及插入數(shù)據(jù)的實例:
create database school; //建立庫SCHOOL
use school; //打開庫SCHOOL
create table teacher //建立表TEACHER
(
id int(3) auto_increment not null primary key, //id設(shè)置為主關(guān)鍵字,并自動設(shè)值,也就是添加的時候,你不必向ID字段寫內(nèi)容
name char(10) not null,
address varchar(50) default '深圳', //設(shè)置默值為深圳
year date
); //建表結(jié)束
//以下為插入字段
insert into teacher values('','glchengang','建平一中','1976-10-10'); //ID不用寫內(nèi)容
insert into teacher values('','jack','建平一中','1975-12-23');
1. 查看數(shù)據(jù)庫的索引空間大小
在MySQL Workbench中運行以下SQL語句:
— 以GB為單位
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024*1024), 6), ‘ GB’) AS ‘Total Index Size’
FROM
information_schema.TABLES
WHERE
table_schema LIKE ‘database’;
— 以MB為單位
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024), 6), ‘ MB’) AS ‘Total Index Size’
FROM
information_schema.TABLES
WHERE
table_schema LIKE ‘database’;
其中,database是待查看數(shù)據(jù)庫的名稱,例如:lsqdb%。運行結(jié)果如下圖所示:
2. 查看數(shù)據(jù)庫的數(shù)據(jù)空間大小
在MySQL Workbench中運行以下SQL語句:
— 以GB為單位
SELECT
CONCAT(ROUND(SUM(data_length)/(1024*1024*1024), 6), ‘ GB’) AS ‘Total Data Size’
FROM
information_schema.TABLES
WHERE
table_schema LIKE ‘database’;
— 以MB為單位
SELECT
CONCAT(ROUND(SUM(data_length)/(1024*1024), 6), ‘ MB’) AS ‘Total Data Size’
FROM
information_schema.TABLES
WHERE
table_schema LIKE ‘database’;
其中,database是待查看數(shù)據(jù)庫的名稱,例如:lsqdb%。運行結(jié)果如下圖所示:
3. 查看數(shù)據(jù)庫中所有表的信息
在MySQL Workbench中運行以下SQL語句,查看數(shù)據(jù)庫中所有表的表名、表行數(shù)、數(shù)據(jù)空間大小、索引空間大小和總大?。?/p>
SELECT
CONCAT(table_schema,’.’,table_name) AS ‘Table Name’,
table_rows AS ‘Number of Rows’,
CONCAT(ROUND(data_length/(1024*1024),6),’ MB’) AS ‘Data Size’,
CONCAT(ROUND(index_length/(1024*1024),6),’ MB’) AS ‘Index Size’,
CONCAT(ROUND((data_length+index_length)/(1024*1024),6),’ MB’) AS’Total Size’
FROM
information_schema.TABLES
WHERE
table_schema LIKE ‘database’;
其中,database是待查看數(shù)據(jù)庫的名稱,例如:lsqdb%。
1.查看索引
(1)單位是GB
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024*1024),
2),
'
GB')
AS
'Total
Index
Size'
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
'database';
+------------------+
|
Total
Index
Size
|
+------------------+
|
1.70
GB
|
+------------------+
(2)單位是MB
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024),
2),
'
MB')
AS
'Total
Index
Size'
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
'database';
其中“database”為你所要查看的數(shù)據(jù)庫
2.查看表空間
SELECT
CONCAT(ROUND(SUM(data_length)/(1024*1024*1024),
2),
'
GB')
AS
'Total
Data
Size'
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
'database';
+-----------------+
|
Total
Data
Size
|
+-----------------+
|
3.01
GB
|
+-----------------+
3.查看數(shù)據(jù)庫中所有表的信息
SELECT
CONCAT(table_schema,'.',table_name)
AS
'Table
Name',
CONCAT(ROUND(table_rows/1000000,2),'M')
AS
'Number
of
Rows',
CONCAT(ROUND(data_length/(1024*1024*1024),2),'G')
AS
'Data
Size',
CONCAT(ROUND(index_length/(1024*1024*1024),2),'G')
AS
'Index
Size'
,
CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),2),'G')
AS'Total'FROM
information_schema.TABLES
WHERE
table_schema
LIKE
'database';