CentOS7 yum方式安装MySQL 5.7

在CentOS中默认安装有MariaDB(MySQL的一个分支),安装完成之后可以直接覆盖MariaDB。

MySQL版本号:5.7.28

下载yum repository

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

安装

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

安装MySQL服务器

yum -y install mysql-community-server

这一步我报了个错,

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


Public key for mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm is not installed


 Failing package is: mysql-community-libs-compat-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

原因是Mysql的GPG升级了,需要重新获取
使用以下命令即可

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

启动Mysql

systemctl start  mysqld.service

查看运行状态

systemctl status mysqld.service

找到MySQL root用户的初始密码:

grep "password" /var/log/mysqld.log
[root@localhost download]# grep "password" /var/log/mysqld.log
2022-05-21T01:52:12.613545Z 1 [Note] A temporary password is generated for root@localhost: k1G%1j)g=,rd

使用临时密码连接客户端:

mysql -uroot -p:k1G%1j)g=,rd

如果你的临时密码和我一样,有特殊符号,则会报错

[root@localhost download]# mysql -uroot -pk1G%1j)g=,rd
bash: syntax error near unexpected token `)

所以就换个方式登录

[root@localhost download]# mysql -uroot -p
Enter password:

修改密码安全限制,否则不能使用简单密码
临时修改:

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

永久修改:
MySQL默认的配置文件:
vim /etc/my.cnf

validate_password_policy=0
validate_password_length=1

修改后重启MySQL

service mysqld restart

修改密码:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

授权远程访问:

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456'; 

如果需要远程连接,注意开放3306端口或者关闭防火墙。

MySQL默认的数据文件目录:
show variables like ‘datadir’;
/var/lib/mysql/

MySQL默认错误日志文件:
show variables like ‘log_error’;
/var/log/mysqld.log

--------------------------------------------------------------------------

如果忘记了root密码或者用临时密码无法登录:

vim /etc/my.cnf

在配置文件中加一行skip-grant-tables

[mysqld]
skip-grant-tables

重启数据库服务

service mysqld restart

然后使用mysql命令登录,使用以下密码修改密码。

mysql> update user set authentication_string=password('123456')  where Host='localhost' and User='root';

修改以后,在配置文件中去掉skip-grant-tables,重启数据库服务。
再使用 mysql -uroot -p123456登录。修改密码安全限制和授权远程访问依然要做。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hongcj925

谢谢你的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值