使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失(转)
B.5.3.2 How to Reset the Root Password
If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root. However, this is insecure. For instructions on assigning passwords, see Section 2.18.4, “Securing the Initial MySQL Accounts”.
If you know the root password and want to change it, see Section 13.7.1.6, “SET PASSWORD Syntax”.
If you assigned a root password previously but have forgotten it, you can assign a new password. The following sections provide instructions for Windows and Unix and Unix-like systems, as well as generic instructions that apply to any system.
B.5.3.2.1 Resetting the Root Password: Windows Systems
On Windows, use the following procedure to reset the password for the MySQL 'root'@'localhost' account. To change the password for a rootaccount with a different host name part, modify the instructions to use that host name.
Log on to your system as Administrator.
Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, selectControl Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.
If your server is not running as a service, you may need to use the Task Manager to force it to stop.
Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');Save the file. This example assumes that you name the file
C:\mysql-init.txt.Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
Start the MySQL server with the special
--init-fileoption (notice that the backslash in the option value is doubled):C:\>
cd "C:\Program Files\MySQL\MySQL Server 5.0\bin"
C:\>mysqld-nt --init-file=C:\\mysql-init.txtIf you installed MySQL to a different location, adjust the cd command accordingly.
The server executes the contents of the file named by the
--init-fileoption at startup, changing the'root'@'localhost'account password.To have server output to appear in the console window rather than in a log file, add the
--consoleoption to the mysqld command.If you installed MySQL using the MySQL Installation Wizard, you may need to specify a
--defaults-fileoption. For example:C:\>
mysqld-nt
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
--init-file=C:\\mysql-init.txtThe appropriate
--defaults-filesetting can be found using the Services Manager: From the Start menu, select Control Panel, thenAdministrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose thePropertiesoption. ThePath to executablefield contains the--defaults-filesetting.After the server has started successfully, delete
C:\mysql-init.txt.
You should now be able to connect to the MySQL server as root using the new password. Stop the MySQL server and restart it normally. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
On Unix, use the following procedure to reset the password for the MySQL 'root'@'localhost' account. To change the password for a root account with a different host name part, modify the instructions to use that host name.
The instructions assume that you will start the MySQL server from the Unix login account that you normally use for running it. For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case youmust start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups. If that happens, you will need to either change the ownership of the files to mysql or remove them.
Log on to your system as the Unix user that the MySQL server runs as (for example,
mysql).Stop the MySQL server if it is running. Locate the
.pidfile that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are/var/lib/mysql/,/var/run/mysqld/, and/usr/local/mysql/data/. Generally, the file name has an extension of.pidand begins with eithermysqldor your system's host name.Stop the MySQL server by sending a normal
kill(notkill -9) to the mysqld process. Use the actual path name of the.pidfile in the following command:shell>
kill `cat /mysql-data-directory/host_name.pid`Use backticks (not forward quotation marks) with the
catcommand. These cause the output ofcatto be substituted into thekillcommand.Create a text file containing the following statement on a single line. Replace the password with the password that you want to use.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');Save the file. This example assumes that you name the file
/home/me/mysql-init. The file contains the password, so do not save it where it can be read by other users. If you are not logged in asmysql(the user the server runs as), make sure that the file has permissions that permitmysqlto read it.Start the MySQL server with the special
--init-fileoption:shell>
mysqld_safe --init-file=/home/me/mysql-init &The server executes the contents of the file named by the
--init-fileoption at startup, changing the'root'@'localhost'account password.After the server has started successfully, delete
/home/me/mysql-init.
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.
B.5.3.2.3 Resetting the Root Password: Generic Instructions
The preceding sections provide password-resetting instructions specifically for Windows and Unix and Unix-like systems. Alternatively, on any platform, you can reset the password using the mysql client (but this approach is less secure):
Stop the MySQL server if necessary, then restart it with the
--skip-grant-tablesoption. This enables anyone to connect without a password and with all privileges, and disables account-management statements such asSET PASSWORD. Because this is insecure, you might want to use--skip-grant-tablesin conjunction with--skip-networkingto prevent remote clients from connecting.Connect to the MySQL server using the mysql client; no password is necessary because the server was started with
--skip-grant-tables:shell>
mysqlIn the
mysqlclient, tell the server to reload the grant tables so that account-management statements work:mysql>
FLUSH PRIVILEGES;Then change the
'root'@'localhost'account password. Replace the password with the password that you want to use. To change the password for arootaccount with a different host name part, modify the instructions to use that host name.mysql>
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally (without the --skip-grant-tables and --skip-networking options).
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
介绍一个非常有用的mysql启动参数—— --skip-grant-tables。顾名思义,就是在启动mysql时不启动grant-tables,授权表。有什么用呢?当然是忘记管理员密码后有用。
操作方法:
1、杀掉原来进行着的mysql:
rcmysqld stop
或者:
service mysqld stop
或者:
kill -TERM mysqld
2、以命令行参数启动mysql:
/usr/bin/mysqld_safe --skip-grant-tables &
3、修改管理员密码:
use mysql;
update user set password=password('yournewpasswordhere') where user='root';
flush privileges;
exit;
4、杀死mysql,重启mysql
也可以在配置文件/etc/my.cnf中配置这个参数
忘记MySQL(和PHP搭配之最佳组合) ROOT密码是在MySQL(和PHP搭配之最佳组合)使用中很常见的问题,可是有很多朋友并不会重置ROOT密码,那叫苦啊,我有深有感触,特写此文章与大家交流:
1、编辑MySQL(和PHP搭配之最佳组合)配置文件:
windows环境中:%MySQL(和PHP搭配之最佳组合)_installdir%\my.ini //一般在MySQL(和PHP搭配之最佳组合)安装目录下有my.ini即MySQL(和PHP搭配之最佳组合)的配置文件。
linux环境中:/etc/my.cnf
在[MySQL(和PHP搭配之最佳组合)d]配置段添加如下一行:
skip-grant-tables
保存退出编辑。
2、然后重启MySQL(和PHP搭配之最佳组合)服务
windows环境中:
net stop MySQL(和PHP搭配之最佳组合)
net start MySQL(和PHP搭配之最佳组合)
linux环境中:
/etc/init.d/MySQL(和PHP搭配之最佳组合)d restart
3、设置新的ROOT密码
然后再在命令行下执行:
MySQL(和PHP搭配之最佳组合) -uroot -p MySQL(和PHP搭配之最佳组合)
直接回车无需密码即可进入数据库了。
现在我们执行如下语句把root密码更新为 7758521:
update user set password=PASSWORD("123456") where user='root';
quit 退出MySQL(和PHP搭配之最佳组合)。
4、还原配置文件并重启服务
然后修改MySQL(和PHP搭配之最佳组合)配置文件把刚才添加的那一行删除。
再次重起MySQL(和PHP搭配之最佳组合)服务,密码修改完毕。
修改完毕。
用新密码123456试一下吧,又能登入MySQL(和PHP搭配之最佳组合)的感觉就是不一样吧?
总结:
1. 先杀掉mysqld的进程:
小技巧:让你忘记MySQL密码也不害怕
2. 使用skip-grant-tables这个选项启动MySQL:
小技巧:让你忘记MySQL密码也不害怕
3. 登录修改密码:
小技巧:让你忘记MySQL密码也不害怕
4. 关掉MySQL
小技巧:让你忘记MySQL密码也不害怕
5. 启动MySQL
小技巧:让你忘记MySQL密码也不害怕
以上就是本文给大家介绍的使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失,希望大家喜欢。
http://www.bkjia.com/Mysql/1058276.html
使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失(转)的更多相关文章
- mysql root 密码丢失问题
root密码丢失,我们需要将mysql以不检查权限的方式重新启动. 在mysql的配置文件(/etc/my.cnf)中,[mysqld]下添加一句skip-grant-tables,然后重新启动服务, ...
- MySQL Root密码丢失解决方法总结
1. 检查my.cnf,看看有没有密码......靠这也算一条啊 2. 如果能够重启,首先使用–skip-grant-tables参数重启,然后改密码,再去掉–skip-grant-tables参数重 ...
- CentOS忘记mariadb/mysql root密码解决办法
本文不再更新,可能存在内容过时的情况,实时更新请访问原地址:CentOS忘记mariadb/mysql root密码解决办法: 这里有两种方式实现修改mariadb root密码. mariadb版本 ...
- MySQL root密码忘记解决
--MySQL root密码忘记的解决办法 -----------------------------------2014/03/14 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接My ...
- MySQL root密码忘记后更优雅的解决方法
MySQL root密码忘记后更优雅的解决方法 https://www.jb51.net/article/143453.htm /usr/bin/mysqld_safe --defaults-file ...
- Centos7 之 MariaDB(Mysql) root密码忘记的解决办法
MariaDB(Mysql) root密码忘记的解决办法 1.首先先关闭mariadb数据库的服务 # 关闭mariadb服务命令(mysql的话命令就是将mariadb换成mysql) [root@ ...
- Mac忘记MySQL root密码解决方法(亲测有效)
重置MySQL root密码 重置MySQL root用户的密码: 1)新建一个文本文件sql.txt,写入修改用户密码的SQL语句. MySQL 5.7.6及更高版本写这句: ALTER USER ...
- 几种破解MySQL root密码的几种方法:
几种破解MySQL root密码的几种方法: 方法一 使用phpmyadmin,这是最简单的了,修改mysql库的user表,不过别忘了使用PASSWord函数. 方法二 使用mysqladmin,这 ...
- MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables
MySQL 5.6 root密码丢失,(window平台)使用mysqld –skip-grant-tables启动MySQL服务,出现警告: 1 [Warning] TIMESTAMP with i ...
随机推荐
- Mysql 导入导出数据结构及数据
方式一: mysqldump -ukevin -P3306 --default-character-set=utf8 -p -h10.1.15.123 activity sign_in_user &g ...
- 用jsp写注冊页面
包含单选框.多选框.session的应用,页面自己主动跳转,中文乱码的处理,入门级 对于中文乱码的处理,注意几点:注冊页面数据提交方式为post不能忘了写,页面编码方式为gbk,处理提交信息的doRe ...
- 动态分析maillog日志,把恶意链接直接用防火墙禁止
近期用 postfix + dovecot 搭建了一个邮件server, 被人当做垃圾邮件转发器,经过配置postfix 的黑白名单, postfix 提示成功的 REJECT 了垃圾邮件, 只是还是 ...
- 使用独立PID namespace防止误杀进程
一段错误的代码 首先看一段错误的代码: #!/bin/bash SLICE=100; slppid=1; pidfile=/var/run/vpnrulematch.pid # 停止之前的sleep ...
- ZOJ 1610 间隔染色段树
要长8000仪表板.间染色的范围,问:最后,能看到的颜色,而且颜色一共有段出现 覆盖段 数据对比水 水可太暴力 段树: #include "stdio.h" #include ...
- Ubuntu 32下Android NDK+NEON的配置过程及简单使用举例
1. 利用VMware在Windows7 64位下安装Ubuntu13.10 32位虚拟机: 2. 从 https://developer.android.com/tools/sdk/ndk/in ...
- SharePoint 2013的HTML5特性之响应式布局
今天偶然看到一本书<Pro SharePoint 2013 Branding and Responsive Web Development>,看到SharePoint 2013基于HTML ...
- IIS7 配置 PHP5.5
本文环境: 操作系统:Win7(x64) 中文专业版 PHP :V5.5 首先添加IIS. 控制面板-〉程序-〉打开或关闭Windows功能 1. 勾选“Internet 信息服务” ...
- [置顶] hdu 4699 2个栈维护 or 伸展树
hdu 4699 Editor 题意:对一个数列进行操作,光标位置后面插入一个权值为x的数,删除光标前的那个数,光标左移一位,光标右移一位,求到k位置的最大的前缀和.. 注意这里的k是在光标之前的, ...
- 【淡墨Unity3D Shader计划】一间 创建一个游戏场景 & 第一Shader写作
本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨) ...