centos7源码安装mysql5.7

准备工作:

下载mysql的安装包:mysql-5.7.13.tar.gz  上传到/usr/local  并解压

下载mysql依赖包:boost_1_59_0.tar.gz  上传到/usr/local 并解压

一、替换国内yum源及eprl源

替换阿里yum源:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

替换epel源

wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo

清除yum缓存并生成新的yum缓存

yum clean all && yum makecache

二、删除系统自带的mysql配置文件

rm -rf  /etc/my.cnf ;rm -rf  /etc/my.cnf.d/

三、安装mysql相关依赖

yum install -y wget cmake make bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel

 

四、新建mysql用户及组

groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql

 

五、创建相关目录及文件并设置所属mysql用户组

mkdir -p /data/mysql && chown mysql.mysql /data/mysql
mkdir -p /etc/my.cnf.d/
mkdir -p /var/log/mysql && touch /var/log/mysql/mysqld.log && chown mysql.mysql /var/log/mysql
mkdir -p /var/run/mysqld && touch /var/run/mysqld/mysql.sock &&  touch /var/run/mysqld/mysqld.pid && chown mysql.mysql /var/run/mysqld

 

 六、解压目录

cd  /usr/local 
tar -zxvf mysql-5.7.13.tar.gz 
tar -zxvf boost_1_59_0.tar.gz 

 

 七、预编译

cd  /usr/local/mysql-5.7.13

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysqld.sock \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLED_PROFILING=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_DEBUG=0 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0;

 

八、编译并安装

注意:在编译到70-80%左右会消耗内存或磁盘IO,可以适当调整虚拟机内存,预计安装20-60分钟左右

make -j `grep processor /proc/cpuinfo | wc -l` && make install

 九、修改安装目录目录的用户所属组

chown -R mysql:mysql /usr/local/mysql

 

十、设置环境变量

vim /etc/profile
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /etc/profile

 

十一、初始化mysql

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

注意此处会生成新的密码需自己记录下

十二、设置开机启动

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld &&chmod a+x /etc/init.d/mysqld &&chkconfig --add mysqld &&chkconfig mysqld on

十三、修改配置

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/run/mysqld/mysql.sock
[mysqld_safe]
log-error=/var/log/mysql/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
symbolic-links=0
[client]
default-character-set=utf8
socket=/var/run/mysqld/mysql.sock
[mysql]
default-character-set=utf8
socket=/var/run/mysqld/mysql.sock
!includedir /etc/my.cnf.d

十四、启动mysql

service mysqld start

十五、修改密码:

mysqladmin -uroot -p'初始化生成的密码' password '你需要设置的密码'

 

posted @ 2020-08-26 15:30  凉生墨客  阅读(136)  评论(0编辑  收藏