mysql编译安装(rhel6.5.x86_64)以及配置

74 篇文章 0 订阅
41 篇文章 0 订阅

MySQL是当下最流行的关系型数据库管理系统之一,在WEB应用方面更是有着良好的表现,所以经常被用来作为网站架构的一部分,如LNMP\LAMP中的M都指的是MySQL。在实际生产应用环境中我们一般会采用源码安装的方式来定制MySQL应用,本文将介绍一下mysql-5.7.11版本的编译安装过程,各版本在不同平台下安装可能会有细节差异,请针对各自版本及平台做相应调整。

前期安装环境介绍

1. cmake (版本不能低于2.8.10)

由于mysql5.5以上的版本改用cmake编译了,所以要装cmake(如果可以通过yum源安装满足要求的cmake版本就不需要以下步骤了,直接yum install cmake -y即可)。

[root@rhel6-vm ~]#  wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz   
[root@rhel6-vm ~]#  tar -xzvf cmake-2.8.10.2.tar.gz   
[root@rhel6-vm ~]#  cd cmake-2.8.10.2   
[root@rhel6-vm cmake-2.8.10.2]#  ./configure && make && make install   

2. Boost1.59.0(版本一定要是1.59.0),如果版本为boost版本可以省略这一步,安装包内自带,只需要在cmake的时候指明路径就好

[root@rhel6-vm ~]#wget -O https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[root@rhel6-vm ~]# tar -zxvf boost_1_59_0.tar.gz -C /usr/local/

3. gcc-c++、make、bison、ncurses

以上环境需求和依赖如果可以通过yum解决的就不必源码编译安装了,但是一定要注意 版本号 是否满足要求。

如果提示某个依赖的库缺少,那么可以通过 yum install 依赖名称-devel -y 来解决,例如出现 :

Curses library not found. Please install appropriate package

解决方法:yum install curses-devel -y

进入正式步骤

注意:由于mysql编译安装比较消耗资源,如果是虚拟机的话建议内存和cpu都稍微大一点,这样会节省不少时间,要不然你可以去开一盘LOL了

1.下载mysql安装包并解压(以mysql-boost-5.7.11.tar.gz)

[root@rhel6-vm ~]# tar -zxvf mysql-boost-5.7.11.tar.gz
[root@rhel6-vm ~]# cd mysql-boost-5.7.11

2.编译安装环节

前面说过了mysql5.5以上的版本改用cmake编译了,所以编译安装三部曲得改一改了:

[root@rhel6-vm mysql-boost-5.7.11]# /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data/mysqldb -DWITH_BOOST=/usr/local/boost_1_59_0 -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci 


[root@rhel6-vm mysql-boost-5.7.11]# make

这里写图片描述
[root@rhel6-vm mysql-boost-5.7.11]# make install
这里写图片描述
上述三步如果没有出现明显错误那么mysql数据库可以说基本安装完成,接下来就是基本的配置以及使用了。

3. 为mysql添加用户和用户组

[root@rhel6-vm ~]# groupadd mysql
[root@rhel6-vm ~]# useradd -r -g mysql mysql 

4. 修改mysql目录所有者和组

[root@rhel6-vm ~]# cd /usr/local/mysql   
[root@rhel6-vm mysql]# chown -R mysql:mysql .

5. 修改mysql数据目录所有者和组

[root@rhel6-vm mysql]# cd /data/mysqldb  
[root@rhel6-vm mysql]# chown -R mysql:mysql . 

6.初始化mysql数据库

[root@rhel6-vm mysql]# cd /usr/local/mysql   
[root@rhel6-vm mysql]# ./mysqld --initialize --datadir=/usr/local/mysql/data/mysqldb --basedir=/usr/local/mysql/ --user=mysql

这里写图片描述
这一步要记住你的临时密码,也就是最后一行的那一串字符,后面需要用来进行初始化

7. 复制mysql服务启动配置文件

[root@rhel6-vm mysql]#  cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf  

vim /etc/my.cnf

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/mysqldb

8. 为mysql服务配置启动脚本

[root@rhel6-vm  ~]# cp  /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 

[root@rhel6-vm ~]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/mysqldb
mysqld_pid_file_path=/usr/local/mysql/mysql.pid

[root@rhel6-vm ~]# chmod 755 /etc/init.d/mysqld

9.启动服务并进行测试

[root@rhel6-vm ~]# chkconfig --add mysqld
[root@rhel6-vm ~]# chkconfig mysqld on
[root@rhel6-vm ~]# service mysqld start

这里写图片描述
10. 设置环境变量

[root@rhel6-vm ~]# vim /etc/profile#添加以下内容

export PATH=$PATH:/usr/local/mysql/bin

[root@rhel6-vm ~]# source /etc/profile

11 . 初始化mysql密码

[root@rhel6-vm ~]# mysql -u root -p\)wgpfkhLH6dO
#先用临时密码登录
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
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
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password=password('halo');
#执行此命令进行初始密码修改
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ^DBye
[root@rhel6-vm ~]# clear

[root@rhel6-vm ~]# mysql -u root -phalo
#用新密码进行测试登录OK
mysql: [Warning] Using a password on the command line interface can be insecure.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值