LNMPA+MSSQL动静页面分离(2)

二、安装 Mysql 5.1.x:

1)先安装Google的开源TCMalloc库,可以提高MySQL在高并发情况下的性能

cd /usr/local/src

wget -c
tar zxvf  google-perftools-1.7.tar.gz
cd google-perftools-1.7/
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
cd ../

2)开始安装Mysql 5.1.x

groupadd mysql -g 27
useradd mysql -u 27 -g 27 -c "MySQL Server" -d /var/lib/mysql -m
cd /usr/local/src
tar -zxf mysql-5.1.45.tar.gz
cd mysql-5.1.45
./configure --prefix=/usr/local/mysql --localstatedir=/var/lib/mysql --with-unix-socket-path=/var/lib/mysql/mysql.sock --with-mysqld-user=mysql --enable-assembler --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innodb_plugin,myisam,myisammrg
make && make install
cd ../

cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R mysql.mysql /var/lib/mysql
chgrp -R mysql /usr/local/mysql/.
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod u+x /etc/init.d/mysql
chkconfig --level 345 mysql on
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >>/etc/ld.so.conf
ldconfig
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config
service mysql start
/usr/local/mysql/bin/mysqladmin -u root password wangwang
service mysql restart

3)设置MySQL:

打开“/etc/my.cnf”文件,修改以下设置,如果没有,可手动添加:

关闭远程连接,即3306端口。这是MySQL的默认监听端口。由于此处MySQL只服务于本地脚本,所以不需要远程连接。尽管MySQL内建的安全机制很严格,但监听一个TCP端口仍然是危险的行为,因为如果MySQL程序本身有问题,那么未授权的访问完全可以绕过MySQL的内建安全机制。(你必须确定,你是否真的不需要远程连接mysql,一般数据库地址为localhost的,即使本地数据库,不需要外链)

skip-networking

保存后退出。

修改完my.cnf后,还需要对mysql的用户名、帐号、及默认数据库进行调整

首先先登录mysql,在终端窗口输入

/usr/local/mysql/bin/mysql -u root -p

然后会提示输入密码,输入正确密码后,会出现mysql>提示符。

输入以下命令:

mysql>use mysql;
mysql>select Host,User,Password,Select_priv,Grant_priv from user;
mysql>delete from user where user='';                  (删除user用户)
mysql>delete from user where password='';               (删除user用户)
mysql>delete from user where host='';                     (删除user用户)
mysql>drop database test;             (删除默认的test数据库)
mysql>flush privileges;               (刷新mysql的缓存,让以上设置立即生效)
mysql>quit;

为了使以上优化和安全设置生效,请重启Mysql服务或Linux。

service mysql restart

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/df20e1c137df754de1da8228e84667da.html