yum install -y wget
wget http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
2、安装编译所需依赖包
yum -y install make gcc gcc-c++ cmake bison-devel ncurses ncurses-devel openssl-devel bison
3、创建用户和组
groupadd mysql
useradd -g mysql mysql
4、创建安装目录和数据目录
mkdir -p /usr/local/mysql
mkdir -p /data/mysql/data
5、授权目录为mysql用户和组
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql/data
6、下面编译的时候需要boost 这里首先安装boost(有boost就不需要安装)
mkdir -p /usr/local/boost
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
解压
tar -xvzf boost_1_59_0.tar.gz
7、下载mysql5.7源码包:
cd /mnt
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.33.tar.gz
tar -xvzf mysql-5.7.33.tar.gz
预编译:
cmake -DWITH_BOOST=/usr/local/boost -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DSYSCONFDIR=/etc -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_SSL=system
8、编译安装
make && make install
9、默认配置文件 为/etc/my.cnf
10、初始化mysql数据库
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data/
11、添加环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
让配置理立即生效生效
source /etc/profile
12、拷贝mysql启动文件到/init/启动目录下
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
13、启动mysql数据库
service mysql restart
14、添加启动服务,设置开机启动
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld on