CentOS 7 下使用yum安装MySQL5.7.20

CentOS7默认数据库是mariadb, 但是 好多用的都是mysql ,但是CentOS7的yum源中默认好像是没有mysql的。

上一篇安装的是5.6的但是我想安装5.7的 yum安装是最简单的 尝试过编译安装各种问题,最后就决定用yum。

(经过一段时间的学习又写了一篇用源码安装mysql5.7.22的 点击打开链接)

卸载 Mysql

没有安装过的可以直接跳过

先停掉mysql进程

pkill -9 mysqld

在这里插入图片描述

查看安装的Mysql

 rpm -qa|grep -i mysql

在这里插入图片描述

用命令卸载 yum -y remove

  yum -y remove mysql*

直接没有mysql

下载Mysql源

下载mysql的repo源 这个安装的mysql5.7.20 纠正一下,这源下载的是最新的版本

   [root@localhost ~]# cd /usr/local/src/
   [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
   [root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
   [root@localhost src]#  yum -y install mysql-server 

(也可以指定安装目录 yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server )我没试,这样装环境变量配置都不用你管,装上直接启动就行。安装路径是默认的。

在这里插入图片描述

一路 y

在这里插入图片描述


配置

默认配置文件路径:

配置文件:/etc/my.cnf 
日志文件:/var/log/var/log/mysqld.log 
服务启动脚本:/usr/lib/systemd/system/mysqld.service 
socket文件:/var/run/mysqld/mysqld.pid
  1. 配置 my.cnf
vim /etc/my.cnf
[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

启动

安装完成后,密码为随机密码,需要重置密码。

启动服务

service mysqld restart

首次登录

[root@localhost ~]# grep "password" /var/log/mysqld.log

在这里插入图片描述

可以看到输入 mysql -u root -p 密码 进入。第一次登陆 ,需要重置密码,要不什么也不能操作

在这里插入图片描述

重置密码

为了安全密码,必须包含 数字、字母、符号

踩过的坑啊,设置了好几次。还有这ip不能是% 不知道为什么 反正第一次设置成%没成功 登上去之后再改就可以改了。

把密码改简单的方法 点击链接

  alter user 'root'@'localhost' identified by 'Root!!2018';  

在这里插入图片描述

刷新权限

 flush privileges 

也可以 直接再添加新用户

CREATE USER ‘root‘@‘%‘ IDENTIFIED BY ‘您的密码‘;

增加root用户指定可以任意IP登录,如果想限制只能让指定IP登录请把%替换成IP地址

grant all on *.* to '用户名'@'%' identified by '密码' with grant option;

自启动

systemctl enable mysqld

重新加载某个服务程序的配置文件

systemctl daemon-reload

问题:如果发现找不到密码!

解决:只能通过忘记密码的方式修改密码! 在安装的过程中发现找不到密码?折腾了好长时间 通过修改密码找回之后发现、原来之前安装的数据库在了,就没有生产新的数据库!!用的还是之前的配置。

1.首先看mysql启动了没?初始化数据库了没?一般直接启动数据库可以用
grep "password" /var/log/mysqld.log 看到随机密码了

2.修改MySQL的登录设置:

vi /etc/my.cnf

在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。

3.重新启动mysqld

/etc/init.d/mysqld restart
或者
service mysqld restart

打开数据库

[root@iZuf69vcnr1ik26qj06t0cZ ~]# mysql -uroot -p
Enter password: (直接按回车)
Welcome to the MySQL monitor.  Commands end with ; or \g.
mysql> use mysql
mysql> update user set password=password("12345") where user="root";
mysql> flush privileges;

mysql 5.7的数据库没有了password字段 用的是authentication_string字段

update mysql.user set authentication_string=password('root') where user='root';

修改密码之后在把 my.cnf 改回来

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值