CentOS7下安装MySQL5.7

2021/7/2 19:26:46

本文主要是介绍CentOS7下安装MySQL5.7,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

  1. 安装YUM repo
    由于centos的yum源中没有MySQL,需要到MySQL官网下载yum repo的配置文件
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

然后进行repo的安装

[root@wg001 ~]# rpm -ivh mysql57-community-release-el7-9.noarch.rpm 
警告:mysql57-community-release-el7-9.noarch.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql57-community-release-el7-9  ################################# [100%]
[root@wg001 ~]# 

# yum makecache

之后就可以用yum进行安装了
在安装之前需要把之前的MySQL删掉: 使用

rpm -qa |grep mysql

发现有输出结果,依次删除

rpm -e **** --nodeps

开始安装MySQL

#yum install mysql-community-server

安装时间有点长,在十分钟左右。

启动MySQL

[root@wg001 ~]# systemctl start mysqld

配置MySQL,获取MySQL的临时密码

[root@wg001 ~]# grep  'temporary password' /var/log/mysqld.log 
2018-12-02T14:08:10.483897Z 1 [Note] A temporary password is generated for root@localhost: e%3t6nfd.vrK

登陆数据库

[root@wg001 ~]# mysql -uroot -pe%3t6nfd.vrK
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

可以看到版本号是5.7.24
登陆后需要及时修改密码

mysql> set password=password("ZMedu118118!");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on  *.* to root@"%" identified by "ZMedu118118!";
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges 

注意: 密码不能设置的过于简单,如果太简单会报错。
设置安全选项

# mysql_secure_installation

默认配置文件

配置文件:/etc/my.cnf 
日志文件:/var/log//var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid

本文转自 ID: 互联网老辛 更多内容关注公众号《极客运维之家》,扫码添加:

在这里插入图片描述



这篇关于CentOS7下安装MySQL5.7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程