CentOS 5.5下安裝mysql-5.0.27
下載下傳mysql-5.0.27.tar.gz:
解壓:tar zxvf mysql-5.0.27.tar.gz
# cd mysql-5.0.27
# mkdir /program/mysql
---
# ./configure --prefix=/program/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-Community --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --with-charset=utf8
統一編碼,都使用utf8
--with-collation=utf8_general_ci
--with-charset=utf8
mysql編譯參數說明:根據 ./configure --help 檢視支援配置的參數
如下連結:
錯誤:checking for termcap functions library... configure: error: No curses/termcap library found
# ./configure --prefix=/program/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-Community --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=gbk --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --with-charset=utf8 --with-named-curses-libs=/usr/lib/libncurses.so.5
[root@localhost mysql-5.0.27]# make
出現錯誤:
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/libncurses.so.5'
collect2: ld returned 1 exit status
make[2]: *** [mysql] 錯誤 1
make[2]: Leaving directory `/home/navy/Desktop/mysql-5.0.27/client'
make[1]: *** [all-recursive] 錯誤 1
make[1]: Leaving directory `/home/navy/Desktop/mysql-5.0.27'
make: *** [all] 錯誤 2
解決方法:
檢查是否已經安裝以下的輔助軟體包
[root@localhost mysql-5.0.27]# rpm -q ncurses
ncurses-5.5-24.
[root@localhost mysql-5.0.27]# rpm -q ncurses-devel
package ncurses-devel is not installed
提示ncurses-devel沒有安裝,用yum安裝:
[root@localhost mysql-5.0.27]# yum install ncurses-devel
Setting up Install Process
Total download size: 1.6 M
Is this ok [y/N]: y
Downloading Packages:
Installed: ncurses-devel.i386 0:5.5-24.
Complete!
重新configure,make時再次出現錯誤:
在configure時将選項“--with-named-curses-libs=/usr/lib/libncurses.so.5”去除
make成功!
[root@localhost mysql-5.0.27]# make install
[root@localhost mysql-5.0.27]# useradd mysql //添加 mysql 使用者
[root@localhost mysql-5.0.27]# cd /program/mysql/
[root@localhost mysql]# bin/mysql_install_db --user=mysql
Installing all prepared tables
[root@localhost mysql]# chown -R root:mysql . //設定權限,注意後面有一個 "."
[root@localhost mysql]# chown -R mysql /var/lib/mysql //設定 mysql 目錄權限
[root@localhost mysql]# chgrp -R mysql . //注意後面有一個 "."
[root@localhost mysql]# cp share/mysql/my-huge.cnf /etc/my.cnf
cp:是否覆寫“/etc/my.cnf”? y
[root@localhost mysql]# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld//開機自動啟動 mysql
cp:是否覆寫“/etc/rc.d/init.d/mysqld”? y
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start//啟動 MySQL
Starting MySQL
[root@localhost mysql]# bin/mysqladmin -u root password "要設定的密碼"
[root@localhost mysql]# service mysqld stop//關閉 MySQL
Shutting down MySQL
統一編碼
1.2.1首先要確定centos5以中文方式安裝,我測試過先按英文方式安裝,可後來怎麼也配不上中文字元集。重新用中文方式安裝,字元集都會自動加載了,免去很多煩惱。
如果不放心,确認一下:
vi /etc/sysconfig/i18n (確定其内容是這樣的.)
LANG="zh_CN.UTF-8"
檢視變量:env
export LANG=zh_CN.UTF-8
如果都是這樣,就正确了!
1.2.2修改mysql的配置檔案,使資料庫與伺服器作業系統的字元集設定一緻。
vi /etc/my.cnf 設定(如果沒有發現這個檔案,就建立1個)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8 (增加的關鍵一句,使得資料庫預設以utf8存儲)
當然,修改後,要重新開機資料庫。
再次用mysql -u root -p指令進入資料庫系統,用SHOW VARIABLES LIKE 'character_set_%';指令檢視到如下内容:
+--------------------------+---------------------- ----------------+
| Variable_name | Value |
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /program/mysql/share/mysql/charsets/ |
但這樣還不夠,還要保證用戶端也是用utf8的字元集來操作的。
登入的時候,要用以下指令:mysql --default-character-set=utf8 -u root -p
再次用SHOW VARIABLES LIKE 'character_set_%';指令檢視,結果變成了:
mysql> SHOW VARIABLES LIKE 'character_set_%';
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_results | utf8 |
也可以用set改變編碼,不過退出sql後,不能儲存。
set character_set_client=utf8;
參考文章
<a href="http://forum.lupaworld.com/thread-59469-1-1.html">http://forum.lupaworld.com/thread-59469-1-1.html</a>