非原创,原文转载自: http://snowolf.iteye.com/blog/1625674
要修改MySQL的root密码,有两个先决条件:
•有修改MySQL配置文件的权限
•有重启MySQL服务的权限
先修改配置文件:
# vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
在[mysqld]下增加skip-grant-tables,即跳过权限验证。
然后登录MySQL,修改root密码:
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user SET Password = password('<Your Password>') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
然后把刚才修改的配置文件再改回来,最后重启服务:
# service mysqld restart
停止 MySQL: [确定]
启动 MySQL: [确定]
分享到:
相关推荐
mysql忘记密码解决办法.docmysql忘记密码解决办法.docmysql忘记密码解决办法.doc
如果忘记mysql的密码,请不要着急,这个文档详细教你如何重新设置新密码
mysql数据库密码忘记最简单的解决方案,已通过本人测试通过,希望对大家有所帮助!
mysql需要在关闭服务情况下操作可生效 解决mysql和oracle忘记密码时操作
忘记Mysql密码解决方案 mysql有时候忘记密码了怎么办?我给出案例和说明!一下就解决了!
windows下忘记mysql超级管理员root密码的解决办法
windows10下安装了mysql8.0.19,几天后才使用,忘记了密码,上网上搜索了无数的解决方法,百度果然很坑爹。 现将解决办法记录如下: 1、data文件夹下的xxx.err文件,我没登陆过MYSQL当然里面也就没有密码。 2、那些...
mac 忘了密码怎么办?上图看内容。
不小心忘记MySQL数据库root用户密码?不要害怕,这里有解决办法,步骤很详细,保证可行。对数据库没有损害。
MAC 中mysql密码忘记解决办法 最近项目用到MySQL,之前装过一个,可是忘记了当时设置的密码,然后走上了修改密码的坎坷道路。在百度,Google了一堆资料之后还是,发现处处是给程序员埋的坑。于是下决心,写一篇博客...
两种使用方法
Mac操作系统下MYSQL数据库密码忘记的快速解决办法 1. 在系统偏好 中,中止MYSQL服务.; 2. cd/usr/local/mysql-…../bin sudo ./mysqld_safe--skip-grant-tables 3. 登录MySQL; mysql 4. 置空root用户的密码; ...
假如忘记了 MySQL 的 root 暗码,能够用以下办法重新设置: 1. KILL掉MySQL进程; 2. 用以下指令发动MySQL,以不查看权限的办法发动; mysqld_safe -skip-grant-tables & 3. 然后用空暗码办法运用root用户...
修订版本加了问题解决
mysql5.7安装常见问题,已经忘记密码的解决办法,资料在百度网盘上,链接及密码都有
主要给大家介绍了关于linux/mac安装mysql忘记密码的解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
通常在使用Mysql数据库时,如果长时间没有登陆,或者由于工作交接完成度不高,会导致数据库root登陆密码忘记,本文给大家介绍一种当忘记mysql root密码时的解决办法,一起看看吧
mysql5.6忘记root密码怎么办,用什么方法可以重置root密码呢?下面通过本文给大家介绍Mysql5.6 忘记root密码的解决办法,需要的朋友参考下