mysql-5.7(centos-6.9环境)源码安装

Posted 岑亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql-5.7(centos-6.9环境)源码安装相关的知识,希望对你有一定的参考价值。

2017-12-25

# 配置主机名完整显示
vim /etc/bashrc

  # Turn on checkwinsize
  shopt -s checkwinsize
  [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\[email protected]\H \W]\\$ "

# 配置主机名永久生效
vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=mysql-5.7-master

# 配置主机名临时生效
hostname mysql-5.7-master

# 配置hosts解析
vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.156  mysql-5.7-master master
10.0.0.157  mysql-5.7-slave  slave

# 配置Yum仓库
cd /etc/yum.repos.d
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
wget http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm 
rpm -ivh epel-release-latest-6.noarch.rpm
yum clean all && yum makecache

# 配置SSH互信
ssh-keygen -t rsa
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
ssh-copy-id slave

# 检查残留包
yum list|grep mysql
yum -y remove mysql.x86_64
yum -y remove mysql-libs.x86_64

# 删除默认位置配置文件/etc/my.cnf
rm -rf /etc/my.cnf

# 创建目录
mkdir -p /app/mysql/etc
mkdir -p /data/mysql/my3306

# 创建用户
groupadd dba && useradd mysql -g dba

# 下载源码包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.18.tar.gz

# 解压源码包
tar -zxf mysql-boost-5.7.18.tar.gz -C /usr/local/src/ && cd /usr/local/src/mysql-5.7.18

# 安装依赖包
yum -y install ncurses ncurses-devel gcc libtool gcc-c++ make cmake readline-devel zlib-devel bison perl-Module-Install.noarch 

# 预编译
time cmake -DCMAKE_INSTALL_PREFIX=/app/mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=ON -DWITH_BOOST=/usr/local/src/mysql-5.7.18/boost 
# 重新编译(可选)
make clean
rm -rf CMakeCache.txt

# 编译、安装
make && make install

# 复制配置文件
cp ~/my.cnf /app/mysql/etc/my.cnf
ln -s /app/mysql/etc/my.cnf /etc/my.cnf

# 修改目录所属组、用户
chown -R mysql.dba /app/mysql/
chown -R mysql.dba /data/mysql/

# 初始化数据库
/app/mysql/bin/mysqld --defaults-file=/app/mysql/etc/my.cnf --initialize --basedir=/app/mysql --datadir=/data/mysql/my3306 --tmpdir=/data/mysql/my3306 --user=mysql

# 配置环境变量
vim ~/.bash_profile
MYSQL_BASE=/app/mysql
PATH=$PATH:$HOME/bin:$MYSQL_BASE/bin
source ~/.bash_profile

# 配置ssl登录
mysql_ssl_rsa_setup  --datadir=/data/mysql/my3306

# 复制启动脚本
cp /app/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

# 启动数据库
service mysqld start

# 获取初始化密码
[[email protected]-5.7-master my3306]# grep temporary password /data/mysql/my3306/error.log     
2017-12-22T15:39:53.526557Z 1 [Note] A temporary password is generated for [email protected]: bDjk&nU:h2Zl

[[email protected]-5.7-slave my3306]# grep temporary password /data/mysql/my3306/error.log 
2017-12-25T17:32:27.298337Z 1 [Note] A temporary password is generated for [email protected]: lR(;EGObl8q?

# 登录数据库
mysql -uroot -pbDjk&nU:h2Zl
mysql -uroot -plR(;EGObl8q?

# 修改密码并允许其他机器上客户端登录
set global validate_password_policy=0;

# 重置root密码
ALTER USER root@localhost IDENTIFIED BY [email protected];
grant all privileges on *.* to root@% identified by [email protected] with grant option;  

# 退出并重新登录数据库
mysql -uroot -p[email protected]

# 查看数据库用户及权限
select User,Host,authentication_string,account_locked from mysql.user;

# 设置免密码登陆路径
mysql_config_editor set --login-path=my3306 --user=root --password --port=3306 --socket=/data/mysql/my3306/mysql.sock

# 查看免密码登陆路径
mysql_config_editor print --all

# 删除免密码登陆路径(可选)
mysql_config_editor remove --login-path=my3306

# 本地免密码登陆数据库
mysql --login-path=my3306

# 设置开机启动
chkconfig mysqld on
chkconfig --list | grep mysql

 

以上是关于mysql-5.7(centos-6.9环境)源码安装的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 6.9上安装Mysql 5.7.18 安装

CentOS 6.9安装jdk1.8

CentOS 6.9编译安装LAMP环境,并部署phpMyAdmin,使用XCache优化性能

Centos 6.9 apahce 2.4.29编译安装

Centos 6.9 编译安装cmake 3.10.2

centos 6.9安装python 3.6