linux中关于mysql:8版本初始随机密码登录不上,修改密码的操作

目录

一、文字叙述操作步骤

二、linux实际操作演示


一、文字叙述操作步骤

  1. 修改配置文件

    vi /etc/my.cnf

    • 在 [mysqld] 下 skip-grant-tables # 添加该语句:忽略mysql权限问题,直接登录

  2. 重启mysql

    service mysql restart

  3. 免密登录mysql

    mysql -u root -p # 直接回车

  4. 使用mysql表

    use mysql;

  5. 执行如下语句

    • select host, user, authentication_string, plugin from user; # 查看一下是否可以执行成功

    • update user set host='%',plugin='mysql_native_password',authentication_string='' where user='root';

  6. 再次编辑配置文件

    vi /etc/my.cnf

    • 在 [mysqld] 下注释掉刚才添加的语句 #skip-grant-tables

  7. 再次重启mysql

    service mysql restart

  8. 免密登录mysql

    mysql -u root -p # 直接回车

  9. 执行如下语句设置你的密码

    ALTER user'root'@'%' IDENTIFIED BY '你要设置的密码';

  10. 设置成功,切记要刷新一下

    flush privileges;

  11. 再次执行登录mysql命令,输入密码,可以发现登录成功!

    mysql -u root -p # 输入你刚才设置的密码

二、linux实际操作演示

​​​​​​​[root@hadoop01 /]# vi /etc/my.cnf           # 修改配置文件
[mysqld]
skip-grant-tables     # 添加该语句:忽略mysql权限问题,直接登录
[root@hadoop01 /]# cd /export/servers/mysql-8.0.33/  # 进到我安装的mysql目录,进入mysql 
[root@hadoop01 mysql-8.0.33]# mysql -u root -p
Enter password: 
mysql> use mysql
mysql> select host, user, authentication_string, plugin from user;
mysql> update user set host='%',plugin='mysql_native_password',authentication_string='' where user='root';
mysql> quit
[root@hadoop01 mysql-8.0.33]# vi /etc/my.cnf
[mysqld]
# skip-grant-tables     # 把该语句注释掉,或删除
[root@hadoop01 mysql-8.0.33]# service mysql restart          # 重启mysql
[root@hadoop01 mysql-8.0.33]# mysql -u root -p
mysql> ALTER user'root'@'%' IDENTIFIED BY '你要设置的密码';      # 设置密码       
mysql> flush privileges;                              # 切记一定要刷新一下
mysql> exit
[root@hadoop01 mysql-8.0.33]# mysql -u root -p   # 再次进入mysql,输入密码进去了!!
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.33 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值