Centos7安装MySQL5.7(yum)

Posted believepd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7安装MySQL5.7(yum)相关的知识,希望对你有一定的参考价值。

本人尝试过使用源码安装方式,那叫一个头疼,各种问题,于是采用yum方式安装,没想到如此简单:

此服务器是刚买的,所以以前没有安装过mysql,如果以前安装过mysql的,好像要卸载干净再安装(其实我也不懂~)。

开始吧:

一、安装MySQL

1、配置yum源

# 下载mysql源安装包(默认5.7最新版本)
[[email protected] ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
[[email protected] ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm

检测yum源是否安装成功

[[email protected] ~]# yum repolist enabled | grep "mysql.*-community.*"

技术图片

如上图所示即安装成功

2、安装MySQL

[[email protected] ~]# yum -y install mysql-server

等一会就安装好了

技术图片

默认配置文件路径: 

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

3、配置 my.cnf

[[email protected] ~]# vim /etc/my.cnf
技术图片
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server_id = 1
expire_logs_days = 3

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
my.cnf

4、启动mysql服务

[[email protected] ~]# service mysqld restart

5、查看密码(因为安装好后,第一次登录密码为随机密码)

[[email protected] ~]# grep "password" /var/log/mysqld.log

技术图片

输入 mysql -u root -p 回车,再输入上面的随机密码,回车,即可登录MySQL。

6、重置密码

注意:

  • ip处填localhost,不要填%
  • 密码必须包含数字、字母、符号(为了安全)
mysql> alter user "root"@"localhost" identified by "新密码";

技术图片

记得要刷新权限

mysql> flush privileges;

输入 exit 退出 MySQL,再次登录就可以用设置好的密码了。

7、添加远程登录用户

默认只允许 root 帐户在本地登录,如果要在其它机器上连接MySQL,必须修改 root 允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,可以添加一个新的帐户。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

以上是关于Centos7安装MySQL5.7(yum)的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7 yum安装mysql5.7,查看默认root密码

centos7 yum安装mysql5.7

centos7 yum 安装 mysql5.7

CentOS7 YUM安装与配置 MySQL5.7

CentOS7使用yum在线安装mysql5.7

CentOS7 64位下MySQL5.7安装与配置(YUM)