簡介:
MySQL是一套靈巧的資料庫伺服器軟體,適合應用在中、小型資訊系統。其特性是支持標準的ANSI SQL語句,以及支持多種作業平台(Linux/Windows)。而在Unix/Linux系統上,MySQL更支持多線程執行(Multi-Threads)方式,從而獲得相當好的效能。而且它也是屬於開放源原始碼軟体。
說明:
本文摘要一些使用MySQL的相關概念與使用情境來展示對應之指令用法,以及一些進階的資料供後續參考使用。
版本:
5.1.53-community MySQL Community Server (GPL)
官網文件:
重要概念說明:
1.何謂 Character Sets and Collations
在資料存取時,最重要的就是編碼問題,這是中文比英文麻煩之處MySQL 有二個與編碼相關的設定 : Character Sets(文字編碼) & Collations(連線校對)
- Character Sets(文字編碼)
是一組符號及其編碼(is a set of symbols and encodings)舉例來說:有四個字元『A, B, a, b』,這些字元即所謂的符號 (symbols),而這些符號存在資料庫有特定的編碼方式 (encodings)。譬如:'0' 代表 A, '1' 代表B。
- Collations(連線校對)
是一組用來比較上述文字編碼的規則(is a set of rules for comparing characters in a character set)譬如:上述 A 與 B 進行比較,我們知道 A <>
- Character Sets 與 Collations 的設置
預設的編碼與校對都是 Latin1如何查詢相關設定值?
- show variables like "%character%";
- show variables like "%collation%";
2.MyISAM 與 InnoDB 之差異
- MyISAM
use Table Locking mechanism was the default storage engine for the MySQL relational database management system versions prior to 5.5. The major deficiency of MyISAM is the absence of transactions support.
- InnoDB
use Row Locking mechanism is the default storage engine for MySQL as of MySQL 5.5 provides the standard ACID-compliant transaction features along with foreign key support (Declarative Referential Integrity)
情境與命令:
1.設定使用者密碼:
- SET PASSWORD FOR 'user'@'%.domain' = PASSWORD('newpass');
2.允許遠端連線管理資料庫:
舉例:若MySQL安裝於IP: 10.10.0.103之主機上面,管理者希望由遠端IP:10.10.0.183(xxx-PC)之電腦上面欲連線至10.10.0.103之資料庫主機上進行管理
- 從遠端10.10.0.183(xxx-PC) ping該資料庫主機,會出現底下錯誤訊息:
>mysqladmin --host=10.10.0.103 -u root pingmysqladmin: connect to server at '10.10.0.103' failederror: 'Host 'xxx-PC' is not allowed to connect to this MySQL server'
- 回到資料庫主機(IP:10.10.0.103)執行底下命令,執行授權:
>mysql -u root -ppass
CREATE USER 'root'@'%' IDENTIFIED BY 'pass';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;
ps. 'root'@'%'代表管理者可以從任何一台遠端機器連線進來,若是只限定某些電腦則「%」可以換成指定IP或Hostname
3.刪除遠端授權:
>mysql -u root -p pass
REVOKE ALL PRIVILEGES ON *.* FROM root@`%`;DELETE FROM user WHERE user="root" AND host="%";FLUSH PRIVILEGES;
進階閱讀:
1.mysql-my.cnf(my.ini [in windows]) 設定檔說明
mysqlmy-cnf設定檔說明22.MySQL Replication
3.MySQL Proxy
4.MySQL vs Java
MySQL與Java資料型別對應