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 ...
随机推荐
- Wtl之奇技淫巧篇:一、SDI如何居中显示视图
Wtl的sdi应用,视图默认铺满框架的客户区.视图通常用modeless对话框,所有的界面元素都拥挤在左上角,这明显很丑陋.我们尝试让视图居中显示,保持原始大小,这是个很典型的问题,看似简单,诸多细节 ...
- Struts2的属性驱动与模型驱动的区别
1.Struts2的属性驱动. Struts2的属性驱动指的是在action中JSP页面的每一个form中的name都对应在action中有一个属性与之对应.看下面代码片段: <form act ...
- 在 sublime text 3 中添加 Emmet (ZenCoding)
安装 Emmet 插件: 启动 Sublime Text 3,选择 Preferences>Package Control,点选 Package Control:Install Package: ...
- Oracle 11g RAC客户端使用SCAN IP无法连接问题
Oracle 版本:11.2.0.1.0 客户端:Windows Server 2003/PLSQL Developer Oracle服务器端的ip设置如下: ##公网ip 192.168.135.2 ...
- Spark1.0新特性-->Spark SQL
Spark1.0出来了,变化还是挺大的,文档比以前齐全了,RDD支持的操作比以前多了一些,Spark on yarn功能我居然跑通了.但是最最重要的就是多了一个Spark SQL的功能,它能对RDD进 ...
- 尝鲜CodeBlocks
在寻找跨平台的C++ IDE,就尝试了CodeBlocks,写了个HelloWorld,测试了一下C++11的代码,我很喜欢他的代码着色,看着很清爽. 记得要打开C++11的支持:
- [转载]斐讯K2 A2版免TTL刷BREED不死Bootloader
1:路由器能正常上网,登陆进路由器 (默认密码admin) 2:用浏览器打开这个网址,如果默认ip不是192.168.2.1修改一下.打开后等待即可自动刷入breed. http://192.168. ...
- iOS时间那点事儿–NSTimeZone
NSTimeZone **时区是一个地理名字,是为了克服各个地区或国家之间在使用时间上的混乱. 基本概念: GMT 0:00 格林威治标准时间; UTC +00:00 校准的全球时间; CCD +08 ...
- win7左ctrl和左alt键互换
主要参考这篇文章: http://xyztony1985.blog.163.com/blog/static/3611782011752420104/ 感谢原博主 Windows Registry Ed ...
- codeforce Number of Ways(暴力)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #d ...