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 ...
随机推荐
- thinking in object pool
1.背景 对象池为了避免频繁创建耗时或耗资源的大对象,事先在对象池中创建好一定数量的大对象,然后尽量复用对象池中的对象,用户用完大对象之后放回对象池. 2.问题 目前纵观主流语言的实现方式无外乎3个步 ...
- Reflector反编译.NET文件后修复【转】
反编译后的工程文件用VS2010打开后,在打开窗体时会出现一系列错误提示: 第一种情况: “设计器无法处理第 152 行的代码: base.AutoScaleMode = AutoScaleMode. ...
- 高效的INSERT INTO SELECT和SELECT INTO
1.INSERT INTO SELECT,目标表必须存在,才可批量插入 INSERT INTO 目标表Table(field1,field2,field2,...) SELECT value1,val ...
- linux samba 服务配置及日志管理
2012-01-16 安装samba共需3个rpm包 samba-common-3.0.23c-2.i386.rpm samba-3.0.23c-2.i386.rpm samba-cli ...
- 开发BI系统时的需求分析研究
我们知道MIS,知道ERP,知道GIS等等,这些系统在管理限制上有很多的冲突,管理和被管理,开放和限制等等,然而BI在开始就不是这样的.BI要求的就是易用还要易于扩展,首先是报表,这个是你无条件的需要 ...
- HTML5[6]:多行文本显示省略号
CSS3新增text-overflow: ellipse; 只支持单行文本 如果是多行文本, 在无法完全显示的情况下,可以按下面这样写: overflow:hidden; display: -webk ...
- MyBatis知多少(14)分散的数据库系统
任何一个重要的数据库无疑都会拥有不止一个依赖者.即使该数据库只是简单地被两个Web 应用程序所共享,也有许多事情需要考虑.假设有一个名为网上购物车的Web应用程序,它使用了一个包含类别代码的数据库.就 ...
- 3D全景!这么牛!!
如果你用过网页版的百度地图,你大概3D全景图浏览是一种怎样的酷炫体验:在一个点可以360度环顾周围的建筑.景色,当然也可以四周移动,就像身临其境. 全景图共分为三种: ①球面全景图 利用一张全景图围成 ...
- Spring中加载ApplicationContext.xml文件的方式
Spring中加载ApplicationContext.xml文件的方式 原文:http://blog.csdn.net/snowjlz/article/details/8158560 1.利用Cla ...
- ruby -- 基础学习(一)项目文件夹说明
App文件夹子文件夾功能介绍 (1)controllers 存放驱动业务逻辑的控制器 (2)helpers 存放视图辅助类,一些常用的代码段 (3)mailers Rails ...