1. 首先卸载系统自带的 mysql;
yum remove mysql
2.安装 cmake 及相关软件 ncurses 和 bison;
yum install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel*
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
tar xzfv cmake-2.8.5.tar.gz
cd cmake-2.8.5
./bootstrap
make
make install
查看 cmake 版本
cmake -version
yum install ncurses-devel*
yum install bison
3. 创建 mysql 用户, 创建数据库目录和权限
groupadd mysql
useradd -g mysql mysql
mkdir -p /data/mysql
chown -R root:mysql /data/mysql
4. 下载 mysql 源码并且编译
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.20.tar.gz
tar xzfv mysql-5.6.20.tar.gz
cd mysql-5.6.20
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/
gmake
gmake install
5. 配置 mysql
cd /usr/local/mysql
cp ./support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
在 [mysqld] 段增加
datadir = /data/mysql
wait-timeout = 30
max_connections = 512
max_connect_errors = 10000000
default-storage-engine = MyISAM
在 [mysqld] 段修改
max_allowed_packet = 16M
然后保存退出编辑
初始化数据库
# ./scripts/mysql_install_db --datadir=/data/mysql --basedir=/usr/local/mysql --defaults-file=/etc/my.cnf --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
设置启动脚本变量
编辑 /etc/rc.d/init.d/mysqld
# vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
设置变量环境
# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile (永久生效)
# export PATH=$PATH:/usr/local/mysql/bin (当前生效)
启动服务
# service mysqld start
设置数据库管理员root密码
# mysqladmin -u root password '123456'
# service mysqld restart
参考:http://icooke.blog.51cto.com/4123148/764796
http://www.jb51.net/article/31366.htm