当前位置: 首页 > news >正文

CentOS7 安装 Mysql 5.7:密码查看与修改、更改端口、开机启动

文章目录

  • 下载 MySQL yum包
  • 安装MySQL源
  • 安装MySQL服务端,需要等待一些时间
  • 启动MySQL
  • 修改密码
    • 方式一:临时密码
      • 获取临时密码,MySQL5.7为root用户随机生成了一个密码
      • 通过临时密码登录MySQL,进行修改密码操作
    • 方式二:skip-grant-tables=1
      • 修改/etc/my.cnf,在 [mysqld] 小节下添加一行
      • 重启mysqld 服务
      • 使用 root 用户登录到 mysql
      • 切换到mysql数据库,更新 user 表
      • 删除 skip-grant-tables=1
  • 授权其他机器远程登录
  • 开启开机自启动
  • 更改默认端口
  • 常见操作

下载 MySQL yum包

wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm

安装MySQL源

rpm -Uvh mysql57-community-release-el7-10.noarch.rpm

安装MySQL服务端,需要等待一些时间

yum install -y mysql-community-server

如果提示:

The GPG keys listed for the “MySQL 5.7 Community Server” repository
are already installed but they are not correct for this package. Check
that the correct key URLs are configured for this repository.

Failing package is: mysql-community-libs-compat-5.7.37-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

修改密码

方式一:临时密码

获取临时密码,MySQL5.7为root用户随机生成了一个密码

grep 'temporary password' /var/log/mysqld.log 

通过临时密码登录MySQL,进行修改密码操作

使用临时密码登录后,不能进行其他的操作,否则会报错,这时候我们进行修改密码操作

mysql -uroot -pALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';

方式二:skip-grant-tables=1

修改/etc/my.cnf,在 [mysqld] 小节下添加一行

skip-grant-tables=1

这一行配置让 mysqld 启动时不对密码进行验证

重启mysqld 服务

systemctl restart mysqld

使用 root 用户登录到 mysql

mysql -uroot 

切换到mysql数据库,更新 user 表

use mysql
update user set authentication_string = password('123456'),password_expired = 'N', password_last_changed = now() where user = 'root';

在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string

删除 skip-grant-tables=1

退出 mysql,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1的内容

授权其他机器远程登录

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;FLUSH PRIVILEGES;
vim /etc/my.cnf

开启开机自启动

systemctl enable mysqld
systemctl daemon-reload

更改默认端口

修改/etc/my.cnf,在 [mysqld] 小节下添加一行:

port=你想要的端口号

重启mysqld 服务:

systemctl restart mysqld

常见操作

查看mysql是否启动:service mysqld status启动mysql:service mysqld start停止mysql:service mysqld stop重启mysql:service mysqld restart
http://www.lryc.cn/news/353743.html

相关文章:

  • 专业渗透测试 Phpsploit-Framework(PSF)框架软件小白入门教程(十三)
  • linux替换文件中的字符串
  • 【前端每日基础】day22——js控制结构
  • npm详解
  • ChatGPT-4o 实战 如何快速分析混淆加密和webpack打包的源码
  • 自然资源-各级国土空间总体规划的审查要点及流程总结
  • 电表远传抄表是什么?
  • 【简明指南:Python中的异常处理与稳健代码设计】
  • STM32—HAL-PWM-舵机180(每个频率对应每个角度)
  • MyBatis详细教程!!(入门版)
  • c++ using 关键字
  • AIGC时代算法工程师的面试秘籍(2024.4.29-5.12第十三式) |【三年面试五年模拟】
  • Docker Portainer使用
  • 创新系列-既要保留<a/>标签右键功能, 又不要href导致点击页面刷新, 希望click实现vue-router跳转
  • 【OceanBase诊断调优】—— KVCache 排查手册
  • 核函数的介绍
  • 使用pytorch写一个简单的vae网络用于生成minist手写数字图像
  • Windows平台让标准输入(stdin)的阻塞立即返回
  • Spring中的Aware接口
  • FFmpeg滤镜完整列表
  • 深入探索Python基础:两个至关重要的函数
  • 探索集合python(Set)的神秘面纱:它与字典有何不同?
  • 火山引擎“奇袭”阿里云
  • 牛客网刷题 | BC94 反向输出一个四位数
  • 记一次MySQL执行修改语句超时问题
  • linux fork()函数调用原理
  • 【电控笔记5.9】编码器脉冲计算速度MT法
  • go-zero 实战(4)
  • go语言泛型Generic最佳实践 --- slices包
  • 【神经网络结构可视化】使用 Visualkeras 可视化 Keras / TensorFlow 神经网络结构