centos下 mysql5.7.16编译安装

14 篇文章 0 订阅
11 篇文章 0 订阅

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, 大功告成~

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值