centos下 mysql5.7.16编译安装

前端之家收集整理的这篇文章主要介绍了centos下 mysql5.7.16编译安装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

author:nsimple http://nsimple.top\
国内安装源:http://sourceforge.mirrorservice.org/\
系统:centos7_64\
NOTE:实际安装过程中,会遇到各种各样的问题 查看错误信息提示一般都能找到解决方案,本文中仅指出关键的不容易解决错误修复方案

【转自】centos下 mysql5.7.16编译安装-nsimple.top

  1. 安装gcc及其他必要依赖库
shell> yum install gcc gcc-c++ bzip2-devel bzip2-libs python-devel ncurses-devel bison -y

shell> wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
shell> tar -xzvf bzip2-1.0.6.tar.gz
shell> make -f Makefile-libbz2_so
shell> make && make install

#如果仍然出现关于bzip2的问题,请安装/更新较新的python/bzip2-devel
#yum clean all 解决问题:Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
  1. 安装cmake
#安装cmake http://www.cmake.org

shell> wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz
shell> tar -zxvf cmake-3.6.2.tar.gz
shell> cd cmake-3.6.2
shell> ./bootstrap
#CMake has bootstrapped. Now run gmake.
shell> gmake
shell> gmake install
  1. 安装boost(官方要求必须是1.59.0~ 我已经尝试过其他版本)
#The Boost C++ libraries are required to build MysqL (but not to use it). Boost 1.59.0 must be installed. http://www.boost.org/
#http://www.boost.org/more/getting_started/unix-variants.html
shell> wget http://sourceforge.mirrorservice.org/b/bo/boost/boost/1.59.0/boost_1_59_0.tar.gz
shell> tar -zxvf boost_1_59_0.tar.gz -C /usr/local/boost_1_59_0
shell> cd /usr/local/boost_1_59_0
shell> ./bootstrap.sh
shell> ./b2  #MD这一步时间真长(20多分钟) 
#或者
#shell> ./b2 -a -sHAVE_ICU=1 #-a参数,代表重新编译,-sHAVE_ICU=1代表支持Unicode/ICU
shell> ./b2 install #默认安装到当前已解压的目录(下一步 -DWITH_BOOST=此目录)
  1. 安装MysqL-server
#安装MysqL-server 下载Source Code版本
#编译步骤:1. http://dev.MysqL.com/doc/refman/5.7/en/source-installation.html
#编译步骤:2. http://dev.MysqL.com/doc/refman/5.7/en/binary-installation.html#binary-installation-layout
#编译问题:http://dev.MysqL.com/doc/refman/5.7/en/compilation-problems.html

shell> wget http://dev.MysqL.com/get/Downloads/MysqL-5.7/MysqL-5.7.16.tar.gz
shell> tar -zxvf MysqL-5.7.16.tar.gz
#必须加上-DWITH_SYSTEMD=1 可以使用systemd控制MysqL服务,默认是不开启systemd的。
shell> /usr/local/bin/cmake . -DWITH_BOOST=/usr/local/boost_1_59_0 -DCMAKE_INSTALL_PREFIX=/alidata/server/MysqL5.7  
#cmake . -DWITH_BOOST=/usr/local/boost_1_59_0 -DDOWNLOAD_BOOST=1 (如果没有安装BOOST)
shell> make 
shell> make install #这一步复制很多文件会占用大量磁盘空间 如果不够用会提示'复制xxx文件失败'
  1. 配置用户
#Sufficient free memory. If you encounter problems such as “internal compiler error” when compiling large source files,it may be that you have too little memory. If compiling on a virtual machine,try increasing the memory allocation.
shell> groupadd MysqL
shell> useradd -r -g MysqL -s /bin/false MysqL
shell> cat /etc/passwd| grep MysqL #查看MysqL用户是否设置正确
MysqL:x:996:1000::/home/MysqL:/bin/false #正确
  1. 初始化数据库
shell> cd /alidata/server/MysqL5.7
#shell> bin/MysqL_install_db --user=MysqL # Before MysqL 5.7.6
#编译参数:http://dev.MysqL.com/doc/refman/5.7/en/server-system-variables.html --basedir:指定安装目录
shell> bin/MysqLd --initialize --basedir=/alidata/server/MysqL5.7 --datadir=/alidata/server/MysqL5.7/data --user=MysqL # MysqL 5.7.6 and up
#上一步执行成功,生成初始化密码(GU7ueCwVru?x): A temporary password is generated for root@localhost: GU7ueCwVru?x
shell> bin/MysqL_ssl_rsa_setup              # MysqL 5.7.6 and up
shell> chown -R root .
shell> chown -R MysqL data
  1. 修改 /etc/my.cnf
#创建启动必需目录并赋予权限
shell> mkdir /alidata/log /alidata/pid
shell> chown -R MysqL.MysqL /alidata/log /alidata/pid
#修改 /etc/my.cnf
shell> vi /etc/my.cnf
[MysqLd]
datadir=/alidata/server/MysqL5.7/data
socket=/tmp/MysqL.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run MysqLd under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[MysqLd_safe]
log-error=/alidata/log/MysqLd.log
pid-file=/alidata/pid/MysqLd.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
  1. 启动MysqLd
shell> cd /alidata/server/MysqL5.7
shell> cp support-files/MysqL.server /etc/init.d/MysqLd
shell> /etc/init.d/MysqLd start
#或者service MysqLd start
  1. MysqL相关命令加入环境变量
shell> export PATH=$PATH:/alidata/server/MysqL5.7/bin
  1. 进入MysqL命令行,修改下root初始化密码
shell> MysqL -uroot -p
password:
MysqL> show databases;
#ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
MysqL>  ALTER USER root@localhost IDENTIFIED BY '123456';

然后用新密码登录,ok,大功告成~

原文链接:https://www.f2er.com/centos/379985.html

猜你在找的CentOS相关文章