centos下 mysql5.7.16编译安装

来源:互联网 发布:java else 必须 编辑:程序博客网 时间:2024/05/16 12:51

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 -yshell> wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gzshell> tar -xzvf bzip2-1.0.6.tar.gzshell> make -f Makefile-libbz2_soshell> 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.orgshell> wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gzshell> tar -zxvf cmake-3.6.2.tar.gzshell> cd cmake-3.6.2shell> ./bootstrap#CMake has bootstrapped.  Now run gmake.shell> gmakeshell> 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.htmlshell> wget http://sourceforge.mirrorservice.org/b/bo/boost/boost/1.59.0/boost_1_59_0.tar.gzshell> tar -zxvf boost_1_59_0.tar.gz -C /usr/local/boost_1_59_0shell> cd /usr/local/boost_1_59_0shell> ./bootstrap.shshell> ./b2  #MD这一步时间真长(20多分钟) #或者#shell> ./b2 -a -sHAVE_ICU=1 #-a参数,代表重新编译,-sHAVE_ICU=1代表支持Unicode/ICUshell> ./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.htmlshell> wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16.tar.gzshell> 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 mysqlshell> useradd -r -g mysql -s /bin/false mysqlshell> 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?xshell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and upshell> chown -R root .shell> chown -R mysql data
  1. 修改 /etc/my.cnf
#创建启动必需目录并赋予权限shell> mkdir /alidata/log /alidata/pidshell> chown -R mysql.mysql /alidata/log /alidata/pid#修改 /etc/my.cnfshell> vi /etc/my.cnf[mysqld]datadir=/alidata/server/mysql5.7/datasocket=/tmp/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-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.logpid-file=/alidata/pid/mysqld.pid## include all files from the config directory#!includedir /etc/my.cnf.d
  1. 启动mysqld
shell> cd /alidata/server/mysql5.7shell> cp support-files/mysql.server /etc/init.d/mysqldshell> /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 -ppassword: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 0