Home Database Mysql Tutorial 找回MySQLroot密码的解决方案

找回MySQLroot密码的解决方案

Jun 07, 2016 pm 02:51 PM
main password retrieve article solution

以下的文章主要讲述的是在LINUX操作系统下装MySQL数据库之后,不小心把MySQL ROOT的密码弄丢或是在修改初始密码时,忘记了新的密码的实际解决方案,下面就是具体方案的描述,希望在你今后的学习中会有所帮助。 因为MySQL密码存储于数据库MySQL中的user表中所

  以下的文章主要讲述的是在LINUX操作系统下装MySQL数据库之后,不小心把MySQL ROOT的密码弄丢或是在修改初始密码时,忘记了新的密码的实际解决方案,下面就是具体方案的描述,希望在你今后的学习中会有所帮助。

  因为MySQL密码存储于数据库MySQL中的user表中所以只需要将我windows 2003下的MySQL中的user表拷贝过来覆盖掉就行了

  在c:\MySQL\data\MySQL\(linux 则一般在/var/lib/MySQL/MySQL/)目录下有三个user表相关文件user.frm、user.MYD、user.MYI

  user.frm //user表样式文件

  user.MYD //user表数据文件

  user.MYI //user表索引文件

  为保险起见,三个都拷贝过来,不过其实如果之前在要恢复的那个MySQL上没有更改过表结构的话,只要拷贝user.MYD就行了

  然后

  #. /etc/rc.d/init.d/MySQL stop  
  #. /etc/rc.d/init.d/MySQL start  
  #MySQL -u root -p XXXXXX 

  好了,可以用windows 2003下MySQL密码登陆了

  MySQL>use MySQL  
  MySQL>update user set Password=PASSWORD('xxxxxx') where User='root'; 

  这时候会出错,提示user表只有读权限

  我分析了一下原因,只这样的,因为user.*文件的权限分配是windows 2003下的,在windows 2003下我ls -l一看权限是666

  在linux下我一看,拷过来后权限变成了600(其实正常情况下600就行了,只不过这里的文件属主不是MySQL,拷过来后的属主变为了MySQL root,所以会出现权限不够,这时候如果你改成权限666则可以了,当然这样不好,没有解决问题的实质),在/var/lib/MySQL/MySQL/下ls -l看了一下

  再

  #chown -R MySQL:MySQL user.*  
  #chmod 600 user.*  
  //OK,DONE 

  重起一下MySQL

  重新连接

  MySQL>use MySQL  
  MySQL>update user set Password=PASSWORD('xxxxxx') where User='root';  
  MySQL>FLUSH PRIVILEGES; 

  有一点值得注意:如果你windows 下MySQL如果是默认配置的话,注意要还要执行

  MySQL>delete from user where User='';  
  MySQL>delete from user where Host='%';  
  MySQL>FLUSH PRIVILEGES; 

  好了,到这里恢复密码过程就完成了

  这个方法么就是有点局限性,你必须也具备另外的user表文件

  其他还有几种方法

  其它方法一(这个是网上流传较广的方法,MySQL中文参考手册上的)

  1. 向MySQLd server 发送kill命令关掉MySQLd server(不是 kill -9),存放进程ID的文件通常在MySQL的数据库所在的目录中。

  killall -TERM MySQLd

  你必须是UNIX的MySQL root用户或者是你所运行的SERVER上的同等用户,才能执行这个操作。

  2. 使用`--skip-grant-tables' 参数来启动 MySQLd。 (LINUX下/usr/bin/safe_MySQLd --skip-grant-tables , windows下c:\MySQL\bin\MySQLd --skip-grant-tables)

  3. 然后无密码登录到MySQLd server ,

  >use MySQL  
  >update user set passwordpassword=password("new_pass") where user="root";  
  >flush privileges; 

  你也可以这样做:

  `MySQLadmin -h hostname -u user password 'new password''。 

  4. 载入权限表: `MySQLadmin -h hostname flush-privileges' ,或者使用 SQL 命令`FLUSH PRIVILEGES'。

  5.killall -TERM MySQLd

  6.用新密码登陆

  其它方法二

  直接用十六进制编辑器编辑user.MYD文件

  不过这个里面我要说明一点,我这里编辑的时候发现个问题,加密的密码串有些是连续存储的,有些的最后两位被切开了,后两位存储在后面其他地方.这一点我还没想明白.还有注意一点就是编辑的是加密过的密码串,也就是说你还是需要另外有user表文件。这种方法和我最上面介绍的方法的区别在于,这种方法直接编辑linux下的user表文件,就不需要重新改文件属主和权限了

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? Apr 11, 2024 am 09:10 AM

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

How to set router WiFi password using mobile phone (using mobile phone as tool) How to set router WiFi password using mobile phone (using mobile phone as tool) Apr 24, 2024 pm 06:04 PM

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

Oracle NVL function common problems and solutions Oracle NVL function common problems and solutions Mar 10, 2024 am 08:42 AM

Common problems and solutions for OracleNVL function Oracle database is a widely used relational database system, and it is often necessary to deal with null values ​​during data processing. In order to deal with the problems caused by null values, Oracle provides the NVL function to handle null values. This article will introduce common problems and solutions of NVL functions, and provide specific code examples. Question 1: Improper usage of NVL function. The basic syntax of NVL function is: NVL(expr1,default_value).

Incorrect password, beware BitLocker warning Incorrect password, beware BitLocker warning Mar 26, 2024 am 09:41 AM

This article will explore how to solve the problem of wrong password, especially the need to be careful when dealing with BitLocker warnings. This warning is triggered when an incorrect password is entered multiple times in BitLocker to unlock the drive. Usually, this warning occurs because the system has a policy that limits incorrect login attempts (usually three login attempts are allowed). In this case, the user will receive an appropriate warning message. The complete warning message is as follows: The password entered is incorrect. Please note that continuously entering incorrect passwords will cause the account to be locked. This is to protect the security of your data. If you need to unlock your account, you will need to use a BitLocker recovery key. The password is incorrect, beware the BitLocker warning you receive when you log in to your computer

How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! How can I make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! Mar 15, 2024 pm 04:13 PM

1. How can you make money by publishing articles on Toutiao today? How to earn more income by publishing articles on Toutiao today! 1. Activate basic rights and interests: original articles can earn profits by advertising, and videos must be original in horizontal screen mode to earn profits. 2. Activate the rights of 100 fans: if the number of fans reaches 100 fans or above, you can get profits from micro headlines, original Q&A creation and Q&A. 3. Insist on original works: Original works include articles, micro headlines, questions, etc., and are required to be more than 300 words. Please note that if illegally plagiarized works are published as original works, credit points will be deducted, and even any profits will be deducted. 4. Verticality: When writing articles in professional fields, you cannot write articles across fields at will. You will not get appropriate recommendations, you will not be able to achieve the professionalism and refinement of your work, and it will be difficult to attract fans and readers. 5. Activity: high activity,

Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions Jun 03, 2024 pm 01:25 PM

Common challenges faced by machine learning algorithms in C++ include memory management, multi-threading, performance optimization, and maintainability. Solutions include using smart pointers, modern threading libraries, SIMD instructions and third-party libraries, as well as following coding style guidelines and using automation tools. Practical cases show how to use the Eigen library to implement linear regression algorithms, effectively manage memory and use high-performance matrix operations.

Tutorial on changing wifi password on mobile phone (simple operation) Tutorial on changing wifi password on mobile phone (simple operation) Apr 26, 2024 pm 06:25 PM

Wireless networks have become an indispensable part of our lives with the rapid development of the Internet. In order to protect personal information and network security, it is very important to change your wifi password regularly, however. To help you better protect your home network security, this article will introduce you to a detailed tutorial on how to use your mobile phone to change your WiFi password. 1. Understand the importance of WiFi passwords. WiFi passwords are the first line of defense to protect personal information and network security. In the Internet age, understanding its importance can better understand why passwords need to be changed regularly. 2. Confirm that the phone is connected to wifi. First, make sure that the phone is connected to the wifi network whose password you want to change before changing the wifi password. 3. Open the phone’s settings menu and enter the phone’s settings menu.

What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? What should I do if my Win10 password does not meet the password policy requirements? What to do if my computer password does not meet the policy requirements? Jun 25, 2024 pm 04:59 PM

In the Windows 10 system, the password policy is a set of security rules to ensure that the passwords set by users meet certain strength and complexity requirements. If the system prompts that your password does not meet the password policy requirements, it usually means that your password does not meet the requirements set by Microsoft. standards for complexity, length, or character types, so how can this be avoided? Users can directly find the password policy under the local computer policy to perform operations. Let’s take a look below. Solutions that do not comply with password policy specifications: Change the password length: According to the password policy requirements, we can try to increase the length of the password, such as changing the original 6-digit password to 8-digit or longer. Add special characters: Password policies often require special characters such as @, #, $, etc. I

See all articles