MySQL

資料庫簡介

何謂 SQL


 SQL 是「結構化查詢語言」(Structured Query Language)的簡稱,讀作「Ess Que Ell」或「sequel」。SQL 最初是由 IBM 的研究中心在 1970 年代初期所開發的,是專門用於關連式資料庫的一種查詢語言。利用 SQL 可以用來定義資料庫結構、建立表格、指定欄位型態與長度,也能新增、異動或查詢資料,它已經成為關聯式資料庫的標準語言。
 SQL 的標準化作業,主要是由 ANSI(美國國家標準學會)與 ISO(國際標準組織)這兩個組織所推動的。最初是在 1986 年由 ANSI 制定其標準化規格,隨後在 1992 年時再推出更新的版本,就是所謂的「SQL-92」、「SQL/92」或「SQL2」。目前,新一代的規格仍在持續發展中,即「SQL-99」規格。
 目前市面上的資料庫產品幾乎都以支援 SQL-92 為主,但卻沒有任何一家支援完整的 SQL-92。它們都有少部份的功能不支援,但在某些方面的支援卻比 SQL-92 來得多。例如 IBM 的 DB2 不支援 SQL-92 所有的完整性法則,但在 VIEW 更新法則的支援上,卻比 SQL-92 多。像這些由軟體商獨自擴充的 SQL 是不具相容性的,如:Oracle 的 PL/SQL、Microsoft SQL Server 的 Transact-SQL。
以上取材自 http://chensh.loxa.edu.tw

General Information of MySQL

The MySQL software delivers a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database erver. MySQL Server is intended for missioncritical, heavy-load production systems as well as for embedding into mass-deployed software.

MySQL 的相關套件 (RedHat 9 Apache/2.0.40+PHP 4.22+MySQL 3.23.54a-11)

mysql-server-3.23.54a-11
mysql-devel-3.23.54a-11
mysql-3.23.54a-11
php-mysql-4.2.2-17
以上四個是必要的


mod_auth_mysql-1.11-12
perl-DBD-MySQL-2.1021-3
以上兩個也可安裝

啟動MySQL

# /etc/rc.d/init.d/mysqld
用法: /etc/rc.d/init.d/mysqld {start|stop|status|condrestart|restart}

也可讓它在開機時自動啟動

設定MySQL

如不想以tar-ball方式安裝,而以rpm方式安裝此版(3.23.54a-11),characterset預設為latin1,需在
/etc/my.cnf
[mysqld]區段,加入default-character-set=big5,再重新啟動。否則碰到含有跳脫字元之內碼之中文(許、功、蓋…等字)會成為亂碼。


測試MySQL


#mysqladmin -u root password 'your_password'
建立mysql之root密碼(與系統之root無關)

# mysql -u root -p
再以root之身份,鍵入密碼進入mysql,成功後會出現以下訊息

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 212 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

如要更改目前身份之mysql之密碼則用
#mysqladmin -p password
Enter password:鍵入新密碼

phpMyAdmin

phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web.

安裝phpMyAdmin(RedHat 9/ phpMyAdmin 2.5.4)

  1. $tar -zxvf phpMyAdmin-2.5.4-php.tar.gz -C /var/www/html/
  2. 再將其改名成較方便的路徑名,如phpMyAdmin

設定phpMyAdmin

config.inc.php

$i = 0;
// The $cfg['Servers'] array starts with $cfg['Servers'][1]. Do not use $cfg['Servers'][0].
// You can disable a server config entry by setting host to ''.
$cfg['Servers'][$i]['host'] = 'localhost'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port - leave blank for default port
$cfg['Servers'][$i]['socket'] = ''; // Path to the socket - leave blank for default socket
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['compress'] = FALSE; // Use compressed protocol for the MySQL connection
// (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['controluser'] = 'root'; // MySQL control user settings
// (this user must have read-only,此root與系統的root無關
$cfg['Servers'][$i]['controlpass'] = 'your password'; // access to the "mysql/user"
// and "mysql/db" tables)

$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?選擇http會在browser出現認證視窗
$cfg['PmaAbsoluteUri'] = 'http://your IP/your phpMyAdmin dictionary/';完整的URL路徑

若有裝phpMyAdmin,則兩者mysql root的密碼設一樣比較不會搞混,另外請注意,在phpMyAdmin之web GUI中更改的是mysql的密碼,而非phpMyAdmin的,phpMyAdmin的密碼在phpMyAdmin/config.inc.php內,故此檔之安全性要注意(可設-rw-r----- 1 root apache 34408 8月 8 2000 config.inc.php)

安全性

除以上所提,在apache中,將/your phpMyAdmin dictionary/設成只有部份IP可讀取,這並不影響mysql的作業,只是限制了此phpMyAdmin管理程式所能被執行的IP。