以下的文章主要介紹的是MySQL SUSE SLES11安裝與配置筆記的實際操作過程,我們是在Linux下兩個不同的版本MySQL安裝實戰MySQL5和MySQL4)演示,以下就是文章的而具體內容描述。
Redhat9.2 安裝MySQL5.0
fedora7安裝MySQL
(1) 下載
從MySQL官網 下載到最新的發行版本5.1.45,簡單起見,直接下載SLES11的RPM版本:
- MySQL-server-community-5.1.45-1.sles11.i586.rpm
- MySQL-client-community-5.1.45-1.sles11.i586.rpm
- MySQL-shared-community-5.1.45-1.sles11.i586.rpm
對MySQL版本的選擇,個人意見,如果是作為產品首先考慮穩定性和性能,功能夠用即可,版本上謹慎保守一些,但是作為一般開發用用,追追新也無所謂。
(2) MySQL SUSE SLES11 安裝
1. rpm安裝
- 執行:rpm -ivh MySQL-server-community-5.1.45-1.sles11.i586.rpm
- Preparing... ########################################### [100%]
- 1:MySQL-server-community ########################################### [100%]
- MySQL 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
- To do so, start the server, then issue the following commands:
- /usr/bin/MySQLadmin -u root password 'new-password'
- /usr/bin/MySQLadmin -u root -h ss-server password 'new-password'
- Alternatively you can run:
- /usr/bin/MySQL_secure_installation
- which will also give you the option of removing the test
- databases and anonymous user created by default. This is
- strongly recommended for production servers.
- See the manual for more instructions.
- Please report any problems with the /usr/bin/MySQLbug script!
- Starting MySQL. done
- Giving MySQLd 2 seconds to start
使用ps -ef | grep MySQL 可以看到msyqld進行已經啟動。netstat -nat 可以看到默認的3306端口已經在監聽。rpm的安裝的確是夠簡單。
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
但是這樣的默認安裝,是沒有指定安裝路徑的,因此MySQL不會MySQL SUSE SLES11 安裝到我們期望的地點。因此只好重新來過,先卸載吧:
rpm -e MySQL-server-community-5.1.45-1.sles11
使用--prefix選項重新安裝:
rpm -ivh --prefix=/work/soft/database/MySQL/ MySQL-server-community-5.1.45-1.sles11.i586.rpm
結果發生錯誤:
- error: package MySQL-server-community is not relocatable
居然不能重新定位MySQL SUSE SLES11 安裝路徑,這個就麻煩了。只好重新下載tarbell的版本MySQL-5.1.45.tar.gz,自己動手編譯。
2. 編譯
./configure --prefix=/work/soft/database/MySQL/MySQL5.1 --localstatedir=/work/soft/database/MySQL/MySQLdata --with-charset=utf8 --with-extra-charsets=all --with-client-ldflags=-all-static --with-MySQLd-ldflags=-all-static --with-unix-socket-path=/work/soft/database/MySQL/tmp/MySQL.sock
configure的過程中出現錯誤而中斷:
- checking for termcap functions library... configure: error: No curses/termcap library found
先把這個東西裝好
- gunzip ncurses-5.7.tar.gz
- tar xvf ncurses-5.7.tar
- cd ncurses-5.7/
- ./configure
- make
- make install
安裝ncurses之後,重新configure成功,繼續make,make install完成編譯MySQL SUSE SLES11 安裝。
然後執行scripts/MySQL_install_db.
- Installing MySQL system tables...
- OK
- Filling help tables...
- OK
- To start MySQLd at boot time you have to copy
- support-files/MySQL.server to the right place for your system
- PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
- To do so, start the server, then issue the following commands:
- /work/soft/database/MySQL/MySQL5.1/bin/MySQLadmin -u root password 'new-password'
- /work/soft/database/MySQL/MySQL5.1/bin/MySQLadmin -u root -h ss-server password 'new-password'
- Alternatively you can run:
- /work/soft/database/MySQL/MySQL5.1/bin/MySQL_secure_installation
- which will also give you the option of removing the test
- databases and anonymous user created by default. This is
- strongly recommended for production servers.
- See the manual for more instructions.
- You can start the MySQL daemon with:
- cd /work/soft/database/MySQL/MySQL5.1 ; /work/soft/database/MySQL/MySQL5.1/bin/MySQLd_safe &
- You can test the MySQL daemon with MySQL-test-run.pl
- cd /work/soft/database/MySQL/MySQL5.1/MySQL-test ; perl MySQL-test-run.pl
- Please report any problems with the /work/soft/database/MySQL/MySQL5.1/bin/MySQLbug script!
接著很重要的事情,設置MySQLd的開機啟動:
- cp support-files/MySQL.server /etc/init.d/MySQL
- chkconfig MySQL on
為了方便,將MySQL 的bin目錄加到PATH中,在/etc/profile中加入myslq/bin,順便增加兩個別名方便操作:
- export PATH=$JAVA_HOME/bin:$SOFT_ROOT/database/MySQL/MySQL5.1/bin:$PATH
- alias MySQL_start="MySQLd_safe&"
- alias MySQL_stop="MySQLadmin -uroot -p shutdown"
3. 配置
按照普遍推薦的標准設置,需要增加MySQL的user和group:不過上面的MySQL SUSE SLES11 安裝過程結束後,發現已經存在名為MySQL的user和group了:
- ss-server:/etc # groupadd MySQL
- groupadd: Group `MySQL' already exists.
- ss-server:/etc # useradd MySQL -g MySQL
- useradd: Account `MySQL' already exists.
用ps命令可以看到
- ss-server:/etc # ps -ef | grep MySQL
- root 3743 1 0 18:58 ? 00:00:00 /bin/sh
/work/soft/database/MySQL/MySQL5.1/bin/MySQLd_safe --datadir=
/work/soft/database/MySQL/MySQLdata --pid-file=/
work/soft/database/MySQL/MySQLdata/ss-server.pid- MySQL 3799 3743 0 18:58 ? 00:00:00 /work/soft/database/MySQL/MySQL5.1
/libexec/MySQLd --basedir=/work/soft/database/MySQL/MySQL5.1
--datadir=/work/soft/database/MySQL/MySQLdata --user=MySQL --log-error
=/work/soft/database/MySQL/MySQLdata/ss-server.err --pid-file=/work/soft
/database/MySQL/MySQLdata/ss-server.pid
這裡MySQLd是以MySQL用戶的身份啟動的。
以下是標准的MySQL SUSE SLES11 安裝設置了
1. 設置root帳戶的密碼
- MySQLadmin -u root password 'yourpassword'
2. 本機登錄MySQL, 需要做的事情有: 刪除本機匿名連接的空密碼帳號;容許root用戶是不允許遠程登錄。
- MySQL -uroot -p
然後輸入上面設置的密碼,登錄後在MySQL的命令行中執行:
- MySQL>use MySQL;
- MySQL>delete from user where password="";
- MySQL>update user set host = '%' where user = 'root';
- MySQL>flush privileges;
- MySQL>quit
對於root賬號,如果考慮安全應該新建其他賬號用於遠程登錄,root賬號可以不必開啟遠程登錄。不過對於一般使用,沒有太多安全需求,允許root用戶遠程登錄可以方便管理,畢竟使用專用管理軟件的圖形界面在操作方面要方便的多。