CentOS 5.4编译安装MySQL(vps,小内存优化)

 

1、安装编译环境

[shell]yum install gcc gcc-c++ autoconf automake ncurses-devel make chkconfig[/shell]

2、下载,解压缩

[shell]
wget http://mysql.mirror.tw/Downloads/MySQL-5.1/mysql-5.1.45.tar.gz
tar -xzvf mysql-5.1.45.tar.gz
[/shell]

3、编译

[shell]
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti"
./configure --prefix=/usr/local/mysql --enable-assembler --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=gb2312,gbk,utf8,latin1 --without-debug --with-charset=utf8 --with-collation=utf8_general_ci --with-pthread --enable-static --enable-thread-safe-client
[/shell]

完成后会提示"Thank you for choosing MySQL!"

[shell]make[/shell]

最后会提示“make all win...”

[shell]make install[/shell]

4、添加用户,安装数据库

[shell]
useradd mysql
passwd mysql #设置密码,例如mysql123

cd /usr/local/mysql/
chown -R mysql:mysql ./

#安装数据库,添加默认mysql配置
./bin/mysql_install_db --user=mysql
cp share/mysql/my-medium.cnf /etc/my.cnf
[/shell]

4、配置、开机自启动

[shell]
#经过上述配置后,mysql应该就可以正常启动了
./bin/mysqld_safe --user=mysql &

#下面我们来设置开机启动mysql
kill掉上述测试进程(一般是两个mysqld_safe是一个shell,它来启动mysqld的daemon)
cp share/mysql/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
#之后可以用service mysqld start启动,开机会自动启动
[/shell]

5、my.cnf参数调优

[shell]vim /etc/my.cnf[/shell]

6、安全配置

[shell]
#设置root密码
mysqladmin -u root password ‘new-password’

#删除test数据库、匿名帐户
mysql -u root -p
mysql> DROP DATABASE test; [删除test数据库]
mysql> DELETE FROM mysql.user WHERE user = ''; [删除匿名帐户]
mysql> FLUSH PRIVILEGES; [重载权限]
[/shell]

7、小内存优化

只要不开InnoDB,my-medium.cnf 一般可以保证很小的内存占用和较高的性能了,具体的MySQL内存优化待续。

Leave a Reply

Your email address will not be published. Required fields are marked *