1、下载并安装MySQL官方的 Yum Repository
- 下载地址:Yum Repository
- 下载文件: mysql57-community-release-el7-11.noarch.rpm(或任意指定版本)
- 存放目录:/usr/local (或任意指定位置)
- 安装Repository:
> yum -y install mysql57-community-release-el7-11.noarch.rpm
- 安装MySQL服务器:
> yum -y install mysql-community-server
- 若报错:The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository.
- 原因是Mysql的GPG升级了,需要重新获取。
- 则执行:
> rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 再执行:
> yum install mysql-server
- 则执行:
2、设置密码
- 输入命令查找初始默认密码
> grep "password" /var/log/mysqld.log
- 返回内容:2023-05-01T14:12:19.102033Z 1 [Note] A temporary password is generated for root@localhost: ajaetFH!C4LM
- 登录数据库:mysql -uroot -p
> mysql -uroot -p
- 修改密码:
new password为新密码mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
3、开启mysql的远程访问
- 开启远程访问和访问密码
you password为访问密码mysql> grant all privileges on . to 'root'@'%' identified by 'you password' with grant option; mysql> flush privileges; mysql> exit;
4、添加开机自启动:
> systemctl enable mysqld.services