[rhel6.5]LNMP之编译安装MySQL-5.7.11

  • 关于Nginx的编译安装参照

( “Nginx的编译安装以及简单配置”)
[http://blog.csdn.net/qq_36294875/article/details/79344943]

  • 操作系统环境

操作系统版本: rhel6.5
内核版本: 2.6.32-431.el6.x86_64
主机名称: server6.com
主机IP: 172.25.23.6/24
MySQl软件包:mysql-boost-5.7.11.tar.gz
Cmake软件包:cmake-2.8.12.2-4.el6.x86_64.rpm
使用KVM虚拟机进行编译

  • 编译安装需要注意的几项

    1. 需要确保虚拟机的内存在20G以上,空闲内存需要在10G以上;
    2. 编译需要的内存在2G以上;
    3. 由于是在 虚拟机中进行编译,,即使虚拟机的CPU数目大于2,不建议使用make -j # 的选项;
    4. 编译安装之前,系统上面,如果有通过rpm软件包安装的Mysql,建议卸载;
    5. rhel6.5提供的cmake软件包,过于早,这里使用制作好的RPM软件包;
  • 编译过程中可能出现的错误,以及解决办法

  • 错误1:
CMake Error at cmake/boost.cmake:81 (MESSAGE):
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.

  If you are inside a firewall, you may need to use an http proxy:

  export http_proxy=http://example.com:80

Call Stack (most recent call first):
  cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:443 (INCLUDE)
  • 解决1
  • Mysql5.5.*系列之后,Mysql必须和Boost一起进行编译安装,在上述的软件包里面,提供了boost,需要指定路径;

    -DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项

  • 错误2:

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed

CMake Error at cmake/readline.cmake:64 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:107 (FIND_CURSES)
  cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)
  CMakeLists.txt:471 (MYSQL_CHECK_EDITLINE)
  • 解决2
[root@server6 mysql-5.7.11]# yum install ncurses-devel gcc-c++ -y
  • 错误3
CMake Warning at cmake/bison.cmake:20 (MESSAGE):
  Bison executable not found in PATH
Call Stack (most recent call first):
  sql/CMakeLists.txt:514 (INCLUDE)


CMake Warning at cmake/bison.cmake:20 (MESSAGE):
  Bison executable not found in PATH
Call Stack (most recent call first):
  libmysqld/CMakeLists.txt:142 (INCLUDE)
  • 解决3
[root@server6 mysql-5.7.11]# yum install -y bison -y
  • 根据编译的选项不同,出现的错误可能不同,在每次修改错误重新进行cmake时,建议删除
[root@server6 mysql-5.7.11]# rm -f CMakeCache.txt 
  • 编译的过程
  • 解压软件包并且使用cmake进行安装
[root@server6 local]# tar zxf mysql-boost-5.7.11.tar.gz
[root@server6 local]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
//上面的cmake不是系统自带的;
  • 使用cmake进行编译安装
  • 编译安装的选项

-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNODBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项

  • 执行编译安装
[root@server6 mysql-5.7.11]# cmake 
> -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql\
> -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
> -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNODBASE_STORAGE_ENGINE=1 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DWITH_BOOST=boot/boost_1_59_0/ 增加编译选项
  • 确认cmake执行过程中没有Error,以及Warning
    这里写图片描述
  • 接下来执行make操作
[root@server6 ~]# make
  • 确认make完成之后,执行make install
[root@server6 ~]# make install 
  • 复制Mysql的文件
[root@server6 mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@server6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
  • 修改环境变量
[root@server6 mysql]# vim ~/.bash_profile 
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin/
  • 添加Mysql用户
[root@server6 mysql]# useradd -u 27 -M -d /usr/local/lnmp/mysql/ -s /sbin/nologin mysql
[root@server6 mysql]# id mysql
uid=27(mysql) gid=1001(mysql) groups=1001(mysql)
[root@server6 mysql]# groupmod -g 27 mysql
[root@server6 mysql]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
  • 更改文件的权限,数据目录的属主是Mysql,配置文件目录的属主是root
[root@server6 mysql]# chown mysql.mysql ./ -R 
[root@server6 mysql]# chown root . -R

[root@server6 mysql]# chown mysql data/ -R 
[root@server6 mysql]# ll
total 60
drwxr-xr-x.  2 root mysql  4096 223 10:54 bin
-rw-r--r--.  1 root mysql 17987 22 2016 COPYING
drwxr-xr-x.  2 mysql mysql  4096 223 12:33 data
drwxr-xr-x.  2 root mysql  4096 223 10:52 docs
drwxr-xr-x.  3 root mysql  4096 223 10:52 include
drwxr-xr-x.  4 root mysql  4096 223 10:54 lib
drwxr-xr-x.  4 root mysql  4096 223 10:53 man
drwxr-xr-x. 10 root mysql  4096 223 10:55 mysql-test
-rw-r--r--.  1 root mysql  2478 22 2016 README
drwxr-xr-x. 28 root mysql  4096 223 10:55 share
drwxr-xr-x.  2 root mysql  4096 223 10:55 support-files
  • 数据库的初始化
[root@server6 bin]# mysqld --initialize --user=root
2018-02-23T05:05:51.878670Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-02-23T05:05:51.878713Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-02-23T05:05:51.878717Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-02-23T05:05:55.784047Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-02-23T05:05:56.750108Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-02-23T05:05:57.082715Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3b4b8706-1857-11e8-8ec0-525400a98e38.
2018-02-23T05:05:57.176949Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-02-23T05:05:57.177741Z 1 [Note] A temporary password is generated for root@localhost: )hX;&9frfhy:
  • 需要记住下图中关于密码的内容
    这里写图片描述

  • 启动mysql服务器

[root@server6 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 

[root@server6 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 这里写图片描述

  • 检查端口

[root@server6 mysql]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1011/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1087/master         
tcp        0      0 172.25.23.6:22              172.25.23.250:53574         ESTABLISHED 1159/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      1011/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1087/master         
tcp        0      0 :::3306                     :::*                        LISTEN      4283/mysqld  

这里写图片描述

  • 使用临时密码进行登录,并且修改密码
[root@server6 mysql]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.11

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
er version: 5.7.11

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
# mysql> alter user root@localhost identified by 'westos';
Query OK, 0 rows affected (0.00 sec)
  • 如果需要配置面密登录
[root@server6 mysql]# vim /root/.mysql_secret
westos(新的密码);
[root@server6 mysql]# chmod 600 /root/.mysql_secret

不建议采用上面的方法
* Mysql提供的安全环境配置脚本 建议执行

[root@server6 mysql]# mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL server using password in '/root/.mysql_secret'

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Yes

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Using existing password for root.

Estimated strength of the password: 25 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : No

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : No

 ... skipping.
All done! 
  • 上述脚本根据实际需求进行选择
  • Make过程中出现的错误
  • 错误1
    这里写图片描述
  • 这是我在虚拟机里面进行编译出现的情况,不要采用make -j #,只使用make
  • 错误2
    这里写图片描述
  • 这个虽然只是一个Warining,但是出现的次数过多,会导致Make Error出错;
  • 建议更新cmake版本,或者编译安装cmake;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值