天天看點

mysql SUSE SLES11 安裝配置筆記

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

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不會安裝到我們期望的地點。是以隻好重新來過,先解除安裝吧:

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

居然不能重新定位安裝路徑,這個就麻煩了。隻好重新下載下傳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

參數比較複雜,重要參考了以下兩個google的文章:

mysql configure 參數

http://ipopeye.iteye.com/blog/351536

Mysql編譯安裝參數優化

http://www.iteye.com/topic/123197

configure的過程中出現錯誤而中斷:

checking for termcap functions library... configure: error: No curses/termcap library found

少東西了,沒的說,找到http://www.gnu.org/software/ncurses/,下載下傳到最新版本

http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gz

先把這個東西裝好

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完成編譯安裝。

然後執行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的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安裝設定了

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使用者遠端登入可以友善管理,畢竟使用專用管理軟體的圖形界面在操作方面要友善的多。

至此,mysql的安裝配置完成,可以使用了,收工!