mysql 開發進階篇系列 31 工具篇(mysql串連工具與MyISAM表壓縮公用程式)

來源:互聯網
上載者:User

標籤:user   end   使用   成功   host   通過   src   and   command   

一.mysql 串連工具  

  在mysq提供的工具中,DBA使用最頻繁的莫過於mysql。這裡的mysql是指串連資料庫的用戶端工具。

  1.1 串連選項

-u, -- user=name 指定使用者名稱
-p ,--password[=name] 指定密碼
-h ,--host=name 指定伺服器IP或者網域名稱
-p, --port=# 指定串連連接埠

在實際串連中命令如下:mysql -u 使用者名稱 -p 密碼[[email protected] ~]#  mysql -u root -p
-- 完整的串連命令如下[[email protected] ~]#  mysql -u root -p -h 172.168.18.201 -P 3306Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g.

  1.2 執行選項
    通過 "-e,--execute=name 執行sql語句並退出" 此選項不需要串連到mysql資料庫後再執行,對於一些批處理指令碼很方便,下面是從用戶端直接查詢mysql資料庫中user表的User和Host欄位:

[[email protected] ~]#  mysql -u root -p  mysql -e "select User,Host from user"Enter password: 

    
  串連多個sql 語句用英文分號隔開如   select User,Host from user; select xxx。

二. myisampack(MyISAM表壓縮公用程式)

  myisampack是一個表壓縮公用程式。在壓縮之前需要確認mysqld已關閉或者要壓縮的表不會有其他的sql操作;而且壓縮過程會很佔用cpu資源,建議在伺服器閒置狀態進行。

  可以將資料檔案壓縮到40%-70%,當以後使用表時,解壓縮列需要的資訊被讀入記憶體。當訪問具體的記錄時效能會更好,因為你只需要解壓縮一個記錄。壓縮後的表也將成為一個唯讀表,不能進行DML操作。

--壓縮前,查看test庫中表的資料檔案大小,其中有個a表是myisam類型, 將壓縮MYD檔案

    [[email protected] ~]# cd /usr/local/mysql/data

    [[email protected] data]# cd test    [[email protected] test]# ls -ltr    總用量 24    -rw-r----- 1 mysql mysql   61 8月  24 16:43 db.opt    -rw-r----- 1 mysql mysql 8566 8月  28 14:29 a.frm    -rw-r----- 1 mysql mysql 1024 8月  28 14:32 a.MYI    -rw-r----- 1 mysql mysql  456 8月  28 14:32 a.MYD
-- myisampack先到基地址裡面找到該命令(用rpm安裝可以在根目錄下直接用該命令)[[email protected] ~]# cd /usr/local/mysql/bin

-- 壓縮a表,提示太小無法壓縮[[email protected] bin]# ./myisampack /usr/local/mysql/data/test/a/usr/local/mysql/data/test/a is too small to compress如果壓縮成功,該表就只能讀,不能寫。可以在查看MYD檔案大小。

mysql 開發進階篇系列 31 工具篇(mysql串連工具與MyISAM表壓縮公用程式)

聯繫我們

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