CentOS 7 下使用yum安装MySQL5.7.20 最简单方法

作者:mrr 时间:2024-01-29 11:13:06 

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

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

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

1.卸载  先停掉mysql进程   没有安装过的可以直接跳过


pkill -9 mysqld  
 rpm -qa|grep -i mysql
      

      用命令 yum -y remove




 yum -y remove mysql-community-client-5.6.38-2.el7.x86_64

      卸载不掉的用 rpm -ev

      依次卸载 直到没有

2.下载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 

  配置  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

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

 4.  启动mysql服务

service mysqld restart

 重置密码


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

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

       接下来重置密码:5.7.20 为了安全密码           必须包含 数字字母符号

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

       把密码改简单的方法 https://www.jb51.net/article/150472.htm


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

     最后记得刷新权限;

     flush privileges

    也可以 直接再添加新用户    


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

grant all on *.* to 'root001'@'%' identified by 'Root@@' with grant option;

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

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

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

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

修改MySQL的登录设置:

#vi /etc/my.cnf

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

重新启动mysqld

重新启动mysqld #/etc/init.d/mysqld restart ( service mysqld restart ) use mysql  update user set password=password("12345") where user="root"; mysql 5.7的数据库没有了password字段 用的是authentication_string字段mysql> update mysql.user set authentication_string=password('root') where user='root' ; flush privileges;

修改密码之后在改回来。

总结

以上所述是小编给大家介绍的CentOS 7 下使用yum安装MySQL5.7.20 最简单方法网站的支持!

来源:https://blog.csdn.net/SuperstarSteven/article/details/83894523

标签:centos7,yum,mysql5.7
0
投稿

猜你喜欢

  • python中验证码连通域分割的方法详解

    2022-09-30 11:04:00
  • 详解python中的json的基本使用方法

    2022-03-15 22:29:13
  • 解决Python安装后pip不能用的问题

    2023-05-10 04:52:14
  • jquery获取复选框被选中的值

    2024-04-22 13:05:24
  • Mysql中批量替换某个字段的部分数据(推荐)

    2024-01-14 19:56:04
  • perl ping检测功能脚本代码

    2023-09-27 12:41:47
  • PHP完全二叉树定义与实现方法示例

    2023-07-04 10:49:10
  • Insert into与AddNew哪一个更好?

    2009-10-28 18:30:00
  • SQL实现LeetCode(181.员工挣得比经理多)

    2024-01-17 03:15:01
  • python opencv捕获摄像头并显示内容的实现

    2021-12-08 23:16:24
  • pytorch中关于distributedsampler函数的使用

    2023-01-18 01:10:01
  • python实现去除下载电影和电视剧文件名中的多余字符的方法

    2022-08-17 16:17:59
  • python中的内置函数max()和min()及mas()函数的高级用法

    2023-01-21 18:45:43
  • Asp+Sql 对数据库的各种操作

    2007-09-22 10:38:00
  • 通俗讲解python 装饰器

    2022-04-30 08:20:47
  • IE下img多余5像素空白

    2009-06-08 13:17:00
  • 解决Python 使用h5py加载文件,看不到keys()的问题

    2021-10-04 06:19:15
  • WinHTTP Services 5.1 参考资料

    2010-03-27 20:49:00
  • python 读取二进制 显示图片案例

    2021-10-15 17:27:45
  • ASP无组件上载,带进度条,多文件上载

    2008-10-29 10:03:00
  • asp之家 网络编程 m.aspxhome.com