一、下载安装所必需的依赖包
1、因为高版本mysql都用cmake安装,所以下载cmake
wget http://www.cmake.org/files/v3.0/cmake-3.0.1.tar.gz
tar zxvf cmake-3.0.1.tar.gz
cd cmake-3.0.1
./configure
make && make install
2、下载其它包
wget http://ftp.gnu.org/gnu/bison/bison-3.0.2.tar.gz
安装同上
wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
安装同上
二、建立目录和用户
1、建立mysql安装目录及数据存放目录
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
2、建立用户及用户组
groupadd mysql
useradd -g mysql mysql -s /sbin/nologin
3、赋予目录权限
chown mysql:mysql -R /usr/local/mysql/
或:chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/data
chgrp -R mysql /usr/local/mysql
三、编译安装
1、使用cmake编译mysql
tar zxvf mysql-5.6.20.tar.gz
cd mysql-5.6.20
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
make && make install
2、初始化数据库(创建mysql授权表)
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
3、编辑/usr/local/mysql/my.cnf配置文件
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
如果这个配置文件不在,则cp support-files/my-medium.cnf /usr/local/mysql/my.cnf一个。
四、启动msyql
1、启动mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
2、修改mysql密码
# /usr/local/mysql/bin/mysql -u root
mysql> set password for 'root'@'localhost'=password('密码');
mysql> exit
五、添加mysql为系统服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start