centos7编译安装mysql5.7

时间:2021-09-13 19:19:47

安装依赖:

yum -y install gcc cmake make gcc-c++ ncurses-devel openssl-devel bison ncurses chkconfig lsof

创建用户组及用户:

groupadd mysql   
useradd -g mysql mysql

创建mysql相关目录:

mkdir /usr/local/mysql
chown mysql.mysql -R /usr/local/mysql/
mkdir -p /var/mysql/
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown mysql.mysql -R /var/mysql/

下载及解压boost:

wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/

下载及解压mysql:

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17.tar.gz
tar -zxvf mysql-5.7.17.tar.gz
cd mysql-5.7.17

编译及安装(每条配置以一个空格隔开,结果空格加.):

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -j `grep processor /proc/cpuinfo | wc -l` -DMYSQL_DATADIR=/var/mysql/data  -DWITH_BOOST=/usr/local/boost_1_59_0 -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DMYSQL_USER=mysql .
make && make install

创建mysql配置文件:

mv /etc/my.cnf /etc/my.cnf-`date +%F`   
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

将MySQL数据库的动态链接库共享至系统链接库,这样MySQL服务就可以被其它服务调用了: 

ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/libmysqlclient.so.20

加入运行环境:

echo pathmunge /usr/local/mysql/bin after > /etc/profile.d/mysql.sh   
. /etc/profile

设置开机启动:

chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on

初始化库:

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --
datadir=/var/mysql/data

启动mysql:

/etc/init.d/mysqld start   
service mysqld restart