1. 程式人生 > >mysql在linux上的安裝之二(mysql源代碼安裝)

mysql在linux上的安裝之二(mysql源代碼安裝)

安裝源 mat charset ucs sets big5 evel 解壓 ref


1.下載對應的mysql安裝源代碼包
地址為:http://dev.mysql.com/downloads/mysql/5.1.html

2.假設曾經安裝過則卸載無用過舊的已安裝的mysql
因為非常多linux發行版,都預裝了對應的mysql,一般都是rpm形式的安裝,且mysql的版本號都是比較低的(這個可能是因為兼容性測試的考慮吧)。因此在自己親自安裝mysql之前,請先卸載這些過舊的mysql,保證我們系統的“純凈”。
使用例如以下命令查詢系統中安裝的mysql:
rpm -qa|grep mysql
此命令會模糊匹配軟件名有mysql的rpm安裝包,列出來的這些都能夠把他們刪掉,一次性刪掉,可使用例如以下的一個腳本命令:
for i in `rpm -qa | grep "mysql"`; do rpm -e --allmatches $i; done
運行完上面命令後。假設還有頑固分子沒有被刪除。那就一個一個利用以下的命令來刪除:
rpm -e --allmatches packet-name
假設發現循環依賴問題,那麽packet-name就列出這些循環依賴的安裝包。一次性所有刪除,如:
[[email protected]
/* */ root]# rpm -e --allmatches mysql


安裝源碼版本號的MySQL
3.加入mysql用戶組
groupadd mysql

4.加入mysql用戶,並指定到mysql用戶組
useradd -g mysql mysql

5.解壓縮mysql-version.tar.gz
gunzip < mysql-VERSION.tar.gz | tar -xvf -

6.安裝mysql
cd mysql-VERSION
./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charsets=armscii8,ascii,big5,cp1250,cp1251,cp1256,cp1257,cp850,cp852,cp866,cp932,dec8,eucjpms,euckr,gb2312,gbk,geostd8,greek,hebrew,hp8,keybcs2,koi8r,koi8u,latin1,latin2,latin5,latin7,macce,macroman,sjis,swe7,tis620,ucs2,ujis,utf8 --with-plugins=innodb_plugin
make
make install

7.復制配置文件
shell> cp support-files/my-medium.cnf /etc/my.cnf

8.運行mysql系統數據庫初始化腳本
cd /usr/local/mysql
bin/mysql_install_db --user=mysql

9.設定mysql安裝文件夾權限,設置owner為mysql
chown -R mysql var
chgrp -R mysql .

10.啟動mysql應用
/usr/local/mysql/bin/mysqld_safe --user=mysql &

11.設置rootpassword(數據庫的DBA)
bin/mysqladmin -u root password ‘root’

12.登錄mysql
bin/mysql -uroot -p
Enter password:
登錄成功會看到:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 229
Server version: 5.1.40-log MySQL Community Server (GPL)

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.

mysql>

這時mysql已經裝好了,能夠查看數據庫了,但在正式使用數據庫開發與部署的時候還須要做一些工作:

1.設定配置文件my.cnf

依照需求copy my-***.cnf到/etc/my.cnf

2.改動默認字符集utf8

(1).[client]下增加default-character-set=utf8
(2).[mysqld]下增加default-character-set=utf8

#不修改存儲引擎的話。3、4步能夠略過
3.啟動InnoDB引擎的方法例如以下:
1)關閉mysql的服務
2)改動my.ini
將default-storage-engine=INNODB前的凝視(#)去掉
將skip-innodb這行凝視(加上#)

4.配置innodb參數
1).找到# Uncomment the following if you are using InnoDB tables
去掉innodb_*下的全部#

2).假設安裝mysql的文件夾不是默認的。則須要改動
# mysql 默認安裝文件夾為 /usr/local/mysql/
# mysql 默認表空間文件夾安裝文件夾為 /usr/local/mysql/var/

innodb_data_home_dir=/usr/local/database/mysql/var/
innodb_log_group_home_dir=/usr/local/database/mysql/var/
3).保存後重新啟動mysql服務。

5.設置系統服務

讓linux啟動的時候就啟動mysql服務
shell> cd /usr/local/mysql/
shell> cp support-files/mysql.server /etc/init.d/mysql
shell> chmod 777 /etc/init.d/mysql
shell> chkconfig --add mysql
shell> chkconfig --level 35 mysql on

6.重新啟動MySQL服務
shell> service mysql restart

mysql在linux上的安裝之二(mysql源代碼安裝)