CentOS 7.9 安装 MySQL5.7

cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

环境准备

  1. 卸载原有的mariadb或mysql
rpm -qa | grep -i mysql
rpm -qa | grep -i mariadb

rpm -e mariadb-xxxx
#注:如上命令删除不成功,有别的软件依赖无法删除时,如下操作:
yum remove mariadb-xxxx
或
rpm -e --nodeps mariadb-xxx
  1. 关闭 seLinux
一、查看SELinux状态命令:
  1、/usr/sbin/sestatus -v ##如果SELinux status参数为enabled即为开启状态
  SELinux status: enabled
  2、getenforce ##也可以用这个命令检查

二、关闭SELinux方法:
  1、临时关闭(不用重启机器):
  代码如下:
  setenforce 0 #设置SELinux 成为 permissive 模式
  #setenforce 1 设置SELinux 成为 enforcing 模式

  2、修改配置文件需要重启机器:
  修改/etc/selinux/config 文件
  将SELINUX=enforcing 改为 SELINUX=disabled
  重启机器即可
  1. 下载 mysql 安装源
去 mysql 官网下载链接
https://dev.mysql.com/downloads/repo/yum/
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

yum install -y mysql80-community-release-el7-3.noarch.rpm

ls -la /etc/yum.repos.d/|grep mysql
-rw-r--r--.  1 root root 2076 4月  24 2019 mysql-community.repo
-rw-r--r--.  1 root root 2108 4月  24 2019 mysql-community-source.repo

<!-- 查看所有可用的安装软件列表 关闭其他的mysql软件 打开5.7 并安装mysql -->
yum repolist
yum repolist all |grep mysql
yum -y install yum-utils
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum install -y mysql-community-server mysql
yum-config-manager --enable mysql57-community*
yum install -y mysql-community-server mysql
  1. 启动MySQL 并初始化密码
# 修改 /etc/my.conf 配置 datadir 和 log-error 指向数据目录
[mysqld]
datadir=/data/mysql/data
#datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
#socket=/data/mysql/data/mysql.sock
symbolic-links=0

log-error=/data/mysql/log/mysqld.log
#log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

# 把数据目录修改为 mysql 用户 权限
ls -la /data/
total 28
d-wx--x--x  4 mysql mysql    29 Jul 15 07:10 mysql

systemctl daemon-reload
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
systemctl restart mysqld
systemctl stop mysqld
  1. MySQL用户密码配置
# mysql 第一次安装会初始化一个密码
grep ‘password‘ /data/mysql/log/mysqld.log
mysql -uroot -p‘VNV&P,c3O?EQ‘
alter user ‘root‘@‘localhost‘ identified by ‘Hao.123456‘;
select version();
grant all privileges on *.* to root@‘%‘ identified by ‘Hao.123456‘ with grant option;
flush privileges;
  1. 其他配置,用其他用户启动MySQL
/usr/local/mysql/bin/mysqld --initialize --user=root --basedir=/usr/local/mysql --datadir=/data/gpmm/mysql/data
/usr/local/mysql/bin/mysqld --daemonize --user=root --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
grep ‘temporary password‘ /usr/local/mysql/logs/error.log
grep ‘password‘ /data/mysql/log/mysqld.log
f9/g*:BXn6KG
mysql -uroot -p‘f9/g*:BXn6KG‘
alter user ‘root‘@‘localhost‘ identified by ‘1qaz@WSX‘;
select version();
grant all privileges on *.* to root@‘%‘ identified by ‘1qaz@WSX‘ with grant option;
flush privileges;
修改服务的配置文件
cat /usr/lib/systemd/system/mysqld.service

CentOS 7.9 安装 MySQL5.7

上一篇:MySQL_01数据库概述


下一篇:mysql5.7强制指定驱动表与被驱动表straight_join