centos7编译安装mysql5.7

centos7编译安装mysql5.7

  • 环境说明
  • 下载mysql5.7.25
  • 检查库文件是否存在,如有删除。
  • 添加mysql组和用户
  • 安装依赖包
  • 解压及安装
  • 设置开机启动及环境变量配置
  • 初始化密码

环境说明

系统:centos7.5
数据库:mysql5.7.25

下载mysql5.7.25

查看版本http://mysql.mirror.kangaroot.net/Downloads
uname -a 查看linux是32位还64位,下载相应版本
下载mysql安装的TAR包
wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz

检查库文件是否存在,如有删除。

rpm -qa | grep mysql
rpm -e mysql-libs-5.1.52.x86_64 –nodeps

ps -ef | grep mysql
systemctl stop mysqld.service

rpm -pa | grep mysql
yum remove mysql-xxx-xxx-

rpm -pa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

删除MySQL对应的文件夹
find / -name mysql

添加mysql组和用户

groupadd mysql
useradd -r -g mysql mysql

安装依赖包

yum -y install libaio libaio-devel numactl

解压及安装

tar zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/webservice/mysql
mkdir -p /usr/local/webservice/mysql/data #创建mysql数据库目录

touch /usr/local/webservice/mysql/mysqld.pid
chown -R mysql:mysql /usr/local/webservice/mysql/
touch /var/log/mysqld.log
chown mysql:mysql /var/log/mysqld.log

touch /tmp/mysql.sock
chown mysql:mysql /tmp/mysql.sock

vim /etc/my.cnf

[mysqld]
character-set-server=utf8
user=mysql
port=3306
basedir=/usr/local/webservice/mysql
datadir=/usr/local/webservice/mysql/data
socket=/tmp/mysql.sock
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/opt/mysql/mysqld.pid
 
[client]
port=3306
socket=/tmp/mysql.sock

cd /usr/local/webservice/mysql/bin
注:mysql5.7.6之后使用mysqld
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
记住显示的默认密码:
A temporary password is generated for root@localhost: pF6z6au!

cd /usr/local/webservice/mysql
复制启动脚本到资源目录:
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld

设置开机启动及环境变量配置

chkconfig --level 35 mysqld on

检查mysqld服务是否生效:
chkconfig --list mysqld

启动mysqld服务
systemctl start mysqld

环境变量配置
编辑/etc/profile,加入如下内容:
export PATH=$PATH:/usr/local/webservice/mysql/bin

初始化密码

mysql -uroot -p
mysql> set password = password(‘123456’);
mysql> flush privileges;

添加远程访问权限

mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> select host, user from user;
±----------±----------+
| host | user |
±----------±----------+
| % | root |
| localhost | mysql.sys |
±----------±----------+
mysql> quit;

添加远程登录用户
grant all privileges on . to “用户名”@“IP地址” identified by “密码” with grant option;

grant all privileges on . to “root”@“8.8.8.8” identified by “123456” with grant option;

flush privileges;

重启生效
/etc/init.d/mysqld restart

你可能感兴趣的:(php)