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的安装配置完成,可以使用了,收工!