1、编译安装MySQL需要一些必备的组件,可以直接使用yum安装即可
yum -y install cmake ncurses-devel gcc-c++
2 创建 Mysql用户
useradd mysql
3 分别给mysql创建程序安装目录和数据存储目录,这里将mysql安装在/opt下,数据存储在 /data/mysql下
mkdir /opt/mysql-5.6.39
chown -R mysql.mysql /opt/mysql-5.6.39 (授权)
mkdir /data/mysql/{log,data} -p
chown -R mysql.mysql /data/mysql (授权)
mkdir /var/lib/mysql
chown -R mysql.mysql /var/lib/mysql (授权)
3 下载/解压 Mysql
tar -xvf mysql-5.6.39.tar.gz
编译:
(1)cmake \
-DCMAKE_INSTALL_PREFIX=/opt/mysql-5.6.39 \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
(2)make (大约20分钟)
(3)make install
4 初始化数据库
cd /opt/mysql-5.6.39
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
5 添加service
cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start —启动MySQL
修改vim /etc/profile文件,在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
source /etc/profile