MySQL 8.0 以上版本重置 root 用户密码

MySQL 8.0 以上版本重置 root 用户密码

  1. 在 /etc/my.cnf 文件末尾追加 skip-grant-tables

    1 [root@abdefg mysql]# vim /etc/my.cnf 2 [mysql] 3 # 设置mysql客户端默认字符集 4 default-character-set=utf8mb4 5 6 [mysqld] 7 # 设置3306端口 8 port = 3306 9 # 设置mysql的安装目录 10 basedir=/usr/local/mysql 11 # 设置mysql数据库的数据的存放目录 12 datadir=/usr/local/mysql/data 13 # 允许最大连接数 14 max_connections=200 15 # 服务端默认编码(数据库级别) 16 character-set-server=utf8mb4 17 # 创建新表时将使用的默认存储引擎 18 default-storage-engine=INNODB 19 lower_case_table_names=1 20 max_allowed_packet=16M 21 skip-grant-tables
  2. 重启MySQL服务

     [root@abdefg mysql]# service mysqld restart
    
  3. 免密码登录 root 用户(输入密码时直接回车即可)

    1 [root@abdefg bin]# mysql -uroot -p 2 Enter password: 3 Welcome to the MySQL monitor. Commands end with ; or \g. 4 Your MySQL connection id is 8 5 Server version: 8.0.13 MySQL Community Server - GPL 6 7 Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 8 9 Oracle is a registered trademark of Oracle Corporation and/or its 10 affiliates. Other names may be trademarks of their respective 11 owners. 12 13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 14 15 mysql>
  4. 重置密码

     mysql> use mysql
    

    查询一下

     mysql> select host, user, authentication_string, plugin from user;
    

    执行修改报错

    1 mysql> alter user 'root'@'localhost'IDENTIFIED BY 'newpassword[@123](https://my.oschina.net/u/9520)'; 2 ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    先执行flush privileges;然后会alter成功,要不然会alter失败

    1 mysql> flush privileges; 2 Query OK, 0 rows affected (0.00 sec) 3 4 mysql> alter user 'root'@'localhost'IDENTIFIED BY 'newpassword[@123](https://my.oschina.net/u/9520)'; 5 Query OK, 0 rows affected (0.03 sec) 6 7 mysql> exit 8 Bye
  5. 把/etc/my.cnf 文件末尾的 skip-grant-tables 去掉,重启MySQL服务,修改完成

参考文档:网络蚂蚁 奥斯维克鸡腿学徒

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

MySQL 8.0 以上版本重置 root 用户密码 - HelloWorld