Mysql5.7忘记root密码及mysql5.7修改root密码的方法
作者:mrr 时间:2024-01-24 16:04:29
关闭正在运行的 MySQL :
[root@www.woai.it ~]# service mysql stop运行
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables &为了安全可以这样禁止远程连接:
[root@www.woai.it ~]# mysqld_safe --skip-grant-tables --skip-networking &使用mysql连接server:
[root@www.woai.it ~]# mysql -p更改密码:
mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';*特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了
而是将加密后的用户密码存储于authentication_string字段
mysql> flush privileges;
mysql> quit;
修改完毕。重启
[root@localhost ~]# service mysql restart
然后mysql就可以连接了
但此时操作似乎功能不完全,还要alter user…
mysql> alter user 'root'@'localhost' identified by '123';
这样也可以:
mysql> set password for 'root'@'localhost'=password('123');
重点给大家介绍下mysql 5.7 root密码修改
MySQL管理者密码设置或修改:
依据官方说明5.6以后版本,第一次启动时会在root目录下生产一个随机密码,文件名.mysql_secret。
[root@bright ~]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2015-03-27 23:12:10
:Jj+FTiqvyrF
[root@bright ~]# cd /usr/local/mysql/bin/
[root@bright bin]# ./mysqladmin -u root -h localhost password '123456' -p
Enter password: #此行输入.mysql_secret里第二行内容
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
官方的方式,笔者无论是否使用--skip-grant-tables启动mysql都测试失败,亲们可以测试:
shell>mysql -uroot -p'password' #password即.mysql_secret里的密码
mysql>SET PASSWORD = PASSWORD('newpasswd');
旧版本,安装后ROOT无密码,按如下操作:
方法一:
shell>service mysqld stop #停止mysql服务
shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysql
shell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。
mysql>use mysql;
mysql>update user set password=PASSWORD("123456")where user="root"; #更改密码为 newpassord
mysql>flush privileges; #更新权限
mysql>quit #退出
方法二:
shell>service mysqld stop #停止mysql服务
shell>mysqld_safe --skip-grant-tables & #以不启用grant-tables模式启动mysql
shell>mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。
mysql > set password for root@localhost = password('mysqlroot');
方法三:
shell>/path/mysqladmin -u UserName -h Host password 'new_password' -p
标签:mysql,5.7,root,密码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现双X轴双Y轴绘图的示例详解
2021-10-17 17:33:58
![](https://img.aspxhome.com/file/2023/8/93598_0s.png)
儿童编程python入门
2021-03-12 15:25:06
![](https://img.aspxhome.com/file/2023/5/79645_0s.jpg)
详解将Python程序(.py)转换为Windows可执行文件(.exe)
2022-05-29 20:46:25
![](https://img.aspxhome.com/file/2023/8/105868_0s.png)
SQL事务用法begin tran,commit tran和rollback tran的用法
2024-01-20 01:44:57
重命名SQLServer数据库的方法
2024-01-26 15:40:34
Python面试不修改数组找出重复的数字
2023-08-07 05:04:16
Vue 2.0 服务端渲染入门介绍
2023-07-02 16:58:52
Python实现合并两个有序链表的方法示例
2023-04-02 22:20:46
![](https://img.aspxhome.com/file/2023/0/75250_0s.png)
pytorch通过训练结果的复现设置随机种子
2021-04-19 07:58:53
python解析xml文件实例分享
2021-11-20 07:56:14
![](https://img.aspxhome.com/file/2023/9/123819_0s.jpg)
MySQL 索引和数据表该如何维护
2024-01-26 18:35:16
![](https://img.aspxhome.com/file/2023/6/109796_0s.png)
vue中iframe的使用及说明
2024-05-13 09:37:25
jQuery 选择器的使用
2008-01-21 13:07:00
pyinstaller打包成无控制台程序时运行出错(与popen冲突的解决方法)
2023-05-15 02:03:20
![](https://img.aspxhome.com/file/2023/5/78485_0s.png)
JavaScript中的Math.atan2()方法使用详解
2024-05-03 15:57:13
mysql下优化表和修复表命令使用说明(REPAIR TABLE和OPTIMIZE TABLE)
2024-01-23 08:33:41
详解重置Django migration的常见方式
2022-10-30 13:21:17
Python的Bottle框架基本知识总结
2023-10-09 09:29:24
Python如何获取pid和进程名字
2023-11-11 11:44:11
![](https://img.aspxhome.com/file/2023/8/78458_0s.jpg)
oracle日期分组查询的完整实例
2023-06-26 10:14:13
![](https://img.aspxhome.com/file/2023/4/63374_0s.png)