linux下mysql忘记root密码解决方法
如果使用 MySQL 数据库忘记了root账号密码,可以通过调节配置文件,跳过密码的方式登数据库,
在数据库里面修改账号密码,一般默认的账号是 root
1、编辑 MySQL 配置文件 my.cnf
注意: 以实际 my.cnf 配置文件路径为准
vim /etc/my.cnf
[mysqld]
spik-grant-tables #增加
2、重启 MySQL 服务
注意:以实际 MySQL 启动脚本路径为准
/etc/init.d/mysqld restart
若报错,注意观察my.cnf配置文件中的内容
3、登陆数据库
/usr/bin/mysql 输入如下命令:
注意:以实际 MySQL 执行文件路径为准
mysql> USE mysql;
mysql> UPDATE user SET Password = password ('新密码') WHERE User = 'root' ;
mysql> flush privileges ;
mysql> quit
4、删除或者注释第一步骤中添加的 spik-grant-tables
5、重启 MySQL 服务
/etc/init.d/mysqld restart
6、使用新密码测试
特殊情况:
我这是使用源码安装的mysql,默认配置文件my.cnf(/usr/local/mysql/my.cnf)中的内容都没有配置,都是在启动文件mysqld(/etc/rc.d/init.d/mysqld)中进行配置的
datadir=/data/mysql
basedir=/usr/local/mysql
若按照上述方法进操作,在my.cnf中添加"spik-grant-tables",则重启mysql时报错
正确的解决方法:
根据启动文件mysqld中的datadir和basedir参数相应的启用my.cnf中的选项,然后再添加"spik-grant-tables",mysql重启就不会报错,也能正常按照下面的步骤进行
未修改前的my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# spik-grant-tables
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
修改后的my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# spik-grant-tables
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
# server_id = .....
# socket = .....
skip-grant-tables
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
然后再重启mysql,进行下面的步骤,重置密码后,再把my.cnf中的修改的那四项全部注释掉,再次重启mysql即可。
linux下mysql忘记root密码解决方法的更多相关文章
- Linux 下mysql忘记root密码解决方法
忘记root密码怎么办:1.关闭数据库2.使用-->mysqld_safe --skip-grant-tables &--<启动数据库3.使用空密码进入数据库(mysql命令后直接 ...
- CentOS下MySQL忘记root密码解决方法【转载】
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- 【转】CentOS下MySQL忘记root密码解决方法
原文转自:http://www.cnblogs.com/sbaicl/articles/3132010.html 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在 ...
- CentOS下MySQL忘记root密码解决方法【亲测】
1.修改MySQL的登录设置: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/m ...
- linux下mysql忘记root密码怎么办
Linux下MySQL忘记root密码怎么办? Linux下MySQL忘记root密码怎么办? 1. 修改MySQL配置文件 默认MySQL的配置文件为/etc/my.cnf,在[mysqld]下面添 ...
- MySQL 忘记root密码解决方法,基于Ubuntu 14.10
忘记MySQL root密码解决方法,基于Ubuntu 14.10 忘了mysql密码,从网上找到的解决方案记录在这里. 编辑mysql的配置文件/etc/mysql/my.cnf,在[mysqld] ...
- Linux下mysql忘记root密码
一台机器上的MYSQL服务器很久没用了,忘了root密码无法连接.一时情急,网上搜寻办法,解决,记录在此备用. 修改MySQL的登录设置: //不同的版本的Linux配置文件的位置也不一样,以Lin ...
- linux下mysql忘记root密码的解决方案
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...
- mysql忘记root密码解决方法
1.需求 如何找回root密码 2.流程 a.首先停止数据库 b.在mysqld进程配置文件中添加skip-grant-tables, c.重启数据库 d.改root密码,不用密码直接登录mysql ...
随机推荐
- SecureCrt设置字符编码
SecureCrt设置字符编码,参考:http://www.2cto.com/os/201412/365535.html
- shell编程总结
一.学习 shell脚本之前的基础知识 [linux shell中的特殊符号] 1. * :代表零个或多个字符或数字. test后面可以没有任何字符,也可以有多个字符,总之有或没有都能匹配出来. 2. ...
- javascript方法 call()和apply()的用法
先上代码: apply()方法示例 /*定义一个人类*/ function Person(name,age) { this.name=name; this.age=age; } /*定义一个学生类*/ ...
- CentOS 7 Vmware虚拟机 /root空间不足解决方法(使用gparted live)
1,关闭虚拟机,编辑虚拟机设置,增加虚拟磁盘的大小,我这里增加10GB 2,连接CDrom到ISO文件(gparted-live-0.19.0-1-i486.iso),使用gparted live启动 ...
- Microsoft 2013 新技术学习笔记 三
什么是代码结构的组织?asp.net MVC 5 默认创建出的几个目录的标准含义分别如下: Controllers目录存放MVC模式中的Controler Models目录存放MVC模式中的Model ...
- c与c++中的extern const的区别和联系
最近复习c++,发现了这个东西. c语言里面,我们在一个.c文件中用const定义了一个全局变量后,可以在另一个.c文件中用extern const来引用,但在c++中在链接的时候会报undefine ...
- Raspberry Pi --操作LED
最简单的一个树莓派GPIO操作入门,这里记录以下 先上连接图: 卧槽.图真特么的大 用到了GPIO的GND和#18针脚,这就不上图了,红色的线接的是18针脚,暗色的线接的是GND针脚,下面上Pytho ...
- 【cs229-Lecture19】微分动态规划
内容: 调试强化学习算法(RL算法) LQR线性二次型调节(french动态规划算法) 滤波(kalman filters) 线性二次高斯控制(LGG) Kalman滤波器 卡尔曼滤波(Kalman ...
- 解决Eclipse报errors running builder ‘javascript validator’ on project
导入jquery的js到项目中,Eclipse每次检测到功能代码变化(保存动作触发)就报错: errors running builder ‘javascript validator’ on proj ...
- 快乐的JS正则表达式(开篇)
我不喜欢一开始就去讨论某某有多强大,因为我觉得那样没意思,首先我们的知道它是干什么,对我们有啥用,再去讨论它的强大之处也不迟.那和往常一样我们先来看几个例子. var arr = [1,4,2,5,2 ...