SUSE SLES11 上安裝配置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) 安裝
1. rpm安裝
執行:rpm -ivh MySQL-server-community-5.1.45-1.sles11.i586.rpm
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的安裝的確是夠簡單。
但是這樣的默認安裝,是沒有指定安裝路徑的,因此mysql不會安裝到我們期望的地點。因此只好重新來過,先卸載吧:
使用--prefix選項重新安裝:
結果發生錯誤:
居然不能重新定位安裝路徑,這個就麻煩了。只好重新下載tarbell的版本mysql-5.1.45.tar.gz,自己動手編譯。
2. 編譯
參數比較復雜,重要參考了以下兩個google的文章:
mysql configure 參數
http://ipopeye.javaeye.com/blog/351536
Mysql編譯安裝參數優化
http://www.javaeye.com/topic/123197
configure的過程中出現錯誤而中斷:
少東西了,沒的說,找到http://www.gnu.org/software/ncurses/,下載到最新版本
http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz
先把這個東西裝好
tar xvf ncurses-5.7.tar
cd ncurses-5.7/
./configure
make
make install
安裝ncurses之后,重新configure成功,繼續make,make install完成編譯安裝。
然后執行scripts/mysql_install_db.
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的開機啟動:
chkconfig mysql on
為了方便,將mysql 的bin目錄加到PATH中,在/etc/profile中加入myslq/bin,順便增加兩個別名方便操作:
alias mysql_start="mysqld_safe&"
alias mysql_stop="mysqladmin -uroot -p shutdown"
3. 配置
按照普遍推薦的標准設置,需要增加mysql的user和group:不過上面的安裝過程結束后,發現已經存在名為mysql的user和group了:
groupadd: Group `mysql' already exists.
ss-server:/etc # useradd mysql -g mysql
useradd: Account `mysql' already exists.
用ps命令可以看到:
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安裝設置了
1. 設置root帳戶的密碼
2. 本機登錄mysql, 需要做的事情有: 刪除本機匿名連接的空密碼帳號;容許root用戶是不允許遠程登錄。
然后輸入上面設置的密碼,登錄后在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用戶遠程登錄可以方便管理,畢竟使用專用管理軟件的圖形界面在操作方面要方便的多。
至此,mysql的安裝配置完成,可以使用了,收工!