banner
NEWS LETTER

CentOS7安装mysql5.7

  • Home
  • CentOS7-mysql5-7
Scroll down

本文介绍在CentOS下安装Mysql的全部过程
本案例使用环境:CentOS:7.4,Mysql:5.7

1、下载mysql

下载并安装官方的 yum repository (新建了mysql文件夹)

1
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
  • 安装前需要清理CentOS自带的mysql
    1
    2
    3
    4
    5
    6
    rpm -qa | grep mysql    # 检查是否安装过mysql
    rpm -e --nodeps mysql-****
    rpm -qa | grep mysql
    whereis mysql # 查询所有mysql对应文件夹
    find / -name mysql
    rm -rf **** # 删除相关目录或文件

2、安装相关依赖包

1
yum -y install mysql57-community-release-el7-10.noarch.rpm

3、yum安装mysql

1
yum -y install mysql-community-server

若报以下错误:
/失败的软件包是:mysql-community-libs-compat-5.7.37-1.el7.x86_64
GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
/

原因:
GPG验证不通过,我理解是本机配置的这个软件包对应的公钥不对,签名验证失败。查mysql官网的解决方案,大意是如果使用的4.1以上版本的rpm的话,除了import mysql的公钥到个人用户的配置中,还需要import mysql的公钥到RPM的配置中。
先执行命令: rpm –import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
再执行安装命令:yum -y install mysql-community-server

4、启动mysql

1
service mysqld start

5 查看是否启动成功

1
service mysqld status

6、查看初始密码

1
grep "password" /var/log/mysqld.log

7、进入数据库

1
mysql -uroot -p

8、修改初始密码

1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'   # 注意密码需要有大小写字母数字

9、授权远程登录

1
grant all on *.* to root@'%' identified by 'new password'
  • linux CentOS7下 mysql5.7.25 密码改简单的方法
    在 vim /etc/my.cnf配置文件中增加:
    1
    2
    3
    4
    5
    6
    7
    ----------- my.cnf -------------
    validate_password=off
    default_password_lifetime=0
    //
    # 重新启动mysql
    # 在sql中执行:
    update mysql.user set authentication_string=password('123456') where user='root' ;

请随意打赏

评论