感谢老男孩赐予的知识。 老男孩(QQ:49000448, mail:49000448@qq.com

下载源码包

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-linux-i686-glibc23.tar.gz/from/http://mysql.cdpa.nsysu.edu.tw/

创建mysql用户

groupadd mysql;
useradd -s /sign/nologin -g mysql -M mysql  #-s /sign/nologin禁止其他所有的php,cookie。

编译

./configure --prefix=/usr/local/mysql \
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \
--localstatedir=/usr/local/mysql/data \
--enable-assembler \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread;

安装

make
make install

初始化数据库

拷贝MySQL的配置文件到/etc目录下

cp support-files/my-huge.cnf /etc/my.cnf

创建数据文件夹

mkdir -p /usr/local/mysql/data

生成mysql.sock

/usr/local/mysql/bin/mysql_install_db --user=mysql

将软件的安装目录拥有者改为root用户

chown -R root /usr/local/mysql/

将存放数据库的目录拥有者改为mysql用户

chown -R mysql /usr/local/mysql/data

将软件的安装目录属组改为mysql组

chgrp -R mysql /usr/local/mysql/

启动

/usr/local/mysql/bin/mysqld_safe --user=mysql &

添加开机启动

vi /etc/rc.local

添加一行

/usr/local/mysql/bin/mysqld_safe --user=mysql &