如何检索MySQL用户名和密码?

时间:2022-07-02 02:40:20

I lost my MySQL username and password. How do I retrieve it?

我丢失了MySQL用户名和密码。如何检索?

9 个解决方案

#1


166  

Stop the MySQL process.

停止MySQL进程。

Start the MySQL process with the --skip-grant-tables option.

使用—skip-grant-tables选项启动MySQL进程。

Start the MySQL console client with the -u root option.

使用-u root选项启动MySQL控制台客户端。

List all the users;

所有的用户列表;

SELECT * FROM mysql.user;

Reset password;

重置密码;

UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

But DO NOT FORGET to

但别忘了。

Stop the MySQL process

停止MySQL进程

Start the MySQL Process normally (i.e. without the --skip-grant-tables option)

正常启动MySQL进程(即没有—skip-grant-tables选项)

when you are finished. Otherwise, your database's security could be compromised.

当你完成了。否则,您的数据库的安全性可能会受到影响。

#2


35  

Unfortunately your user password is irretrievable. It has been hashed with a one way hash which if you don't know is irreversible. I recommend go with Xenph Yan above and just create an new one.

不幸的是,您的用户密码是不可挽回的。它是用单向哈希哈希进行哈希的如果你不知道它是不可逆的。我推荐您使用上面的Xenph Yan并创建一个新的。

You can also use the following procedure from the manual for resetting the password for any MySQL root accounts on Windows:

您还可以使用手册中的以下步骤重新设置Windows上任何MySQL根帐户的密码:

  1. Log on to your system as Administrator.
  2. 作为管理员登录您的系统。
  3. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager:
  4. 如果MySQL服务器正在运行,请停止它。对于作为Windows服务运行的服务器,请转到Services manager:

Start Menu -> Control Panel -> Administrative Tools -> Services

启动菜单->控制面板->管理工具->服务

Then 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.

然后在列表中找到MySQL服务,并停止它。如果您的服务器不是作为服务运行的,您可能需要使用任务管理器来强制它停止。

  1. Create a text file and place the following statements in it. Replace the password with the password that you want to use.

    创建一个文本文件并将下列语句放入其中。用您想要使用的密码替换密码。

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    

    The UPDATE and FLUSH statements each must be written on a single line. The UPDATE statement resets the password for all existing root accounts, and the FLUSH statement tells the server to reload the grant tables into memory.

    每个UPDATE和FLUSH语句都必须写在一行上。UPDATE语句重置所有现有根帐户的密码,而FLUSH语句告诉服务器将grant表重新加载到内存中。

  2. Save the file. For this example, the file will be named C:\mysql-init.txt.
  3. 保存文件。对于本例,该文件将命名为C:\mysql-init.txt。
  4. Open a console window to get to the command prompt:

    打开控制台窗口,进入命令提示符:

    Start Menu -> Run -> cmd

    开始菜单->运行-> cmd

  5. Start the MySQL server with the special --init-file option:

    使用特殊的—init-file选项启动MySQL服务器:

    C:\> C:\mysql\bin\mysqld-nt --init-file = C:\mysql-init.txt
    

    If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.

    如果将MySQL安装到C:\ MySQL之外的位置,则相应地调整命令。

    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.

    服务器在启动时执行由—init-file选项命名的文件的内容,更改每个根帐户密码。

    You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.

    如果希望服务器输出显示在控制台窗口中而不是在日志文件中,还可以向命令添加-console选项。

    If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:

    如果您使用MySQL安装向导安装MySQL,您可能需要指定—defaults-file选项:

    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini" --init-file=C:\mysql-init.txt
    

    The appropriate --defaults-file setting can be found using the Services Manager:

    使用服务管理器可以找到适当的-default -file设置:

    Start Menu -> Control Panel -> Administrative Tools -> Services

    启动菜单->控制面板->管理工具->服务

    Find the MySQL service in the list, right-click on it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.

    在列表中找到MySQL服务,右键单击它,然后选择Properties选项。可执行字段的路径包含—defaults-file设置。

  6. After the server has started successfully, delete C:\mysql-init.txt.
  7. 服务器成功启动后,删除C:\mysql .txt。
  8. Stop the MySQL server, then restart it in normal mode again. 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.
  9. 停止MySQL服务器,然后再次以正常模式重启。如果您将服务器作为服务运行,请从Windows Services窗口启动它。如果您手动启动服务器,请使用您通常使用的任何命令。

You should now be able to connect to MySQL as root using the new password.

现在应该可以使用新的密码以root身份连接到MySQL了。

#3


32  

An improvement to the most useful answer here:

对最有用的答案的改进:

1] No need to restart the mysql server
2] Security concern for a MySQL server connected to a network

对于连接到网络的mysql服务器,不需要重新启动mysql服务器

There is no need to restart the MySQL server.

不需要重新启动MySQL服务器。

use FLUSH PRIVILEGES; after the update mysql.user statement for password change.

使用刷新权限;更新后的mysql。密码更改的用户语句。

The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

FLUSH语句告诉服务器将grant表重新加载到内存中,以便它注意到密码的更改。

The --skip-grant-options enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to

skipg -grant选项允许任何人在没有密码和所有特权的情况下连接。因为这是不安全的,你可能想要

use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.

使用—skipg -grant-表与-skip-network,以防止远程客户端连接。

from: reference: resetting-permissions-generic

来自:参考:resetting-permissions-generic

#4


6  

While you can't directly recover a MySQL password without bruteforcing, there might be another way - if you've used MySQL Workbench to connect to the database, and have saved the credentials to the "vault", you're golden.

虽然您不能直接恢复MySQL密码而不使用bruteforce,但是也可以使用另一种方法—如果您使用MySQL Workbench连接到数据库,并将凭据保存到“vault”中,那么您就很幸运了。

On Windows, the credentials are stored in %APPDATA%\MySQL\Workbench\workbench_user_data.dat - encrypted with CryptProtectData (without any additional entropy). Decrypting is easy peasy:

在Windows上,凭据存储在%APPDATA%\MySQL\ workbench_user_data中。用密码保护数据加密(没有任何附加的熵)。解密是容易peasy:

std::vector<unsigned char> decrypt(BYTE *input, size_t length) {
    DATA_BLOB inblob { length, input };
    DATA_BLOB outblob;

    if (!CryptUnprotectData(&inblob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &outblob)) {
            throw std::runtime_error("Couldn't decrypt");
    }

    std::vector<unsigned char> output(length);
    memcpy(&output[0], outblob.pbData, outblob.cbData);

    return output;
}

Or you can check out this DonationCoder thread for source + executable of a quick-and-dirty implementation.

或者,您可以检查一下这个DonationCoder线程,它是一个快速而肮脏的实现的源代码+可执行文件。

#5


3  

If you have root access to the server where mysql is running you should stop the mysql server using this command

如果您具有对正在运行mysql的服务器的根访问权限,那么应该使用此命令停止mysql服务器

sudo service mysql stop

Now start mysql using this command

现在使用这个命令启动mysql。

sudo /usr/sbin/mysqld --skip-grant-tables  --skip-networking &

Now you can login to mysql using

现在可以使用mysql登录

sudo mysql
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Full instructions can be found here http://www.techmatterz.com/recover-mysql-root-password/

完整的指令可以在这里找到http://www.techmatterz.com/recover-mysql-root-password/

#6


1  

Login MySql from windows cmd using existing user:

使用现有用户从windows cmd登录MySql:

mysql -u username -p
Enter password:****

mysql -u用户名-p输入密码:***

Then run the following command:

然后运行以下命令:

mysql> SELECT * FROM mysql.user;

After that copy encrypted md5 password for corresponding user and there are several online password decrypted application available in web. Using this decrypt password and use this for login in next time. or update user password using flowing command:

在复制了相应用户的加密md5密码后,web上可以使用几个在线密码解密应用程序。使用这个解密密码,下次登录时使用这个密码。或使用流畅命令更新用户密码:

mysql> UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

Then login using the new password and user.

然后使用新的密码和用户登录。

#7


0  

Although a strict, logical, computer science'ish interpretation of the op's question would be to require both "How do I retrieve my MySQL username" and "password" - I thought It might be useful to someone to also address the OR interpretation. In other words ...

尽管对op的问题有严格的、逻辑性的、计算机科学的解释,但它要求“我如何检索我的MySQL用户名”和“密码”——我认为它可能对某些人来说是有用的,也可以处理或解释。换句话说……

1) How do I retrieve my MySQL username?

1)如何检索我的MySQL用户名?

OR

2) password

2)密码

This latter condition seems to have been amply addressed already so I won't bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.

后一种情况似乎已经得到了充分的解决,所以我不会为此费心。下面的解决方案是“如何仅保留我的MySQL用户名”。因HIH。公司破产引发

To find your mysql username run the following commands from the mysql shell ...

要找到您的mysql用户名,请运行以下命令从mysql shell…

SELECT User FROM mysql.user;

从mysql.user选择用户;

it will print a table of all mysql users.

它将打印所有mysql用户的表。

#8


0  

IF you happen to have ODBC set up, you can get the password from the ODBC config file. This is in /etc/odbc.ini for Linux and in the Software/ODBC folder in the registry in Windows (there are several - it may take some hunting)

如果您碰巧安装了ODBC,您可以从ODBC配置文件中获取密码。这是在/etc/odbc.Linux的ini和Windows注册表中的Software/ODBC文件夹(有几个-可能需要一些搜索)

#9


0  

Do it without down time

Run following command in the Terminal to connect to the DBMS (you need root access):

在终端运行以下命令连接到DBMS(需要根访问):

sudo mysql -u root -p;

run update password of the target user (for my example username is mousavi and it's password must be 123456):

运行目标用户的更新密码(我的示例用户名为mousavi,密码必须为123456):

UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE user='mousavi';  

at this point you need to do a flush to apply changes:

此时,您需要做一个刷新来应用更改:

FLUSH PRIVILEGES;

Done! You did it without any stop or restart mysql service.

完成了!没有任何停止或重新启动mysql服务。

#1


166  

Stop the MySQL process.

停止MySQL进程。

Start the MySQL process with the --skip-grant-tables option.

使用—skip-grant-tables选项启动MySQL进程。

Start the MySQL console client with the -u root option.

使用-u root选项启动MySQL控制台客户端。

List all the users;

所有的用户列表;

SELECT * FROM mysql.user;

Reset password;

重置密码;

UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

But DO NOT FORGET to

但别忘了。

Stop the MySQL process

停止MySQL进程

Start the MySQL Process normally (i.e. without the --skip-grant-tables option)

正常启动MySQL进程(即没有—skip-grant-tables选项)

when you are finished. Otherwise, your database's security could be compromised.

当你完成了。否则,您的数据库的安全性可能会受到影响。

#2


35  

Unfortunately your user password is irretrievable. It has been hashed with a one way hash which if you don't know is irreversible. I recommend go with Xenph Yan above and just create an new one.

不幸的是,您的用户密码是不可挽回的。它是用单向哈希哈希进行哈希的如果你不知道它是不可逆的。我推荐您使用上面的Xenph Yan并创建一个新的。

You can also use the following procedure from the manual for resetting the password for any MySQL root accounts on Windows:

您还可以使用手册中的以下步骤重新设置Windows上任何MySQL根帐户的密码:

  1. Log on to your system as Administrator.
  2. 作为管理员登录您的系统。
  3. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager:
  4. 如果MySQL服务器正在运行,请停止它。对于作为Windows服务运行的服务器,请转到Services manager:

Start Menu -> Control Panel -> Administrative Tools -> Services

启动菜单->控制面板->管理工具->服务

Then 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.

然后在列表中找到MySQL服务,并停止它。如果您的服务器不是作为服务运行的,您可能需要使用任务管理器来强制它停止。

  1. Create a text file and place the following statements in it. Replace the password with the password that you want to use.

    创建一个文本文件并将下列语句放入其中。用您想要使用的密码替换密码。

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
    FLUSH PRIVILEGES;
    

    The UPDATE and FLUSH statements each must be written on a single line. The UPDATE statement resets the password for all existing root accounts, and the FLUSH statement tells the server to reload the grant tables into memory.

    每个UPDATE和FLUSH语句都必须写在一行上。UPDATE语句重置所有现有根帐户的密码,而FLUSH语句告诉服务器将grant表重新加载到内存中。

  2. Save the file. For this example, the file will be named C:\mysql-init.txt.
  3. 保存文件。对于本例,该文件将命名为C:\mysql-init.txt。
  4. Open a console window to get to the command prompt:

    打开控制台窗口,进入命令提示符:

    Start Menu -> Run -> cmd

    开始菜单->运行-> cmd

  5. Start the MySQL server with the special --init-file option:

    使用特殊的—init-file选项启动MySQL服务器:

    C:\> C:\mysql\bin\mysqld-nt --init-file = C:\mysql-init.txt
    

    If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.

    如果将MySQL安装到C:\ MySQL之外的位置,则相应地调整命令。

    The server executes the contents of the file named by the --init-file option at startup, changing each root account password.

    服务器在启动时执行由—init-file选项命名的文件的内容,更改每个根帐户密码。

    You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.

    如果希望服务器输出显示在控制台窗口中而不是在日志文件中,还可以向命令添加-console选项。

    If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:

    如果您使用MySQL安装向导安装MySQL,您可能需要指定—defaults-file选项:

    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini" --init-file=C:\mysql-init.txt
    

    The appropriate --defaults-file setting can be found using the Services Manager:

    使用服务管理器可以找到适当的-default -file设置:

    Start Menu -> Control Panel -> Administrative Tools -> Services

    启动菜单->控制面板->管理工具->服务

    Find the MySQL service in the list, right-click on it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.

    在列表中找到MySQL服务,右键单击它,然后选择Properties选项。可执行字段的路径包含—defaults-file设置。

  6. After the server has started successfully, delete C:\mysql-init.txt.
  7. 服务器成功启动后,删除C:\mysql .txt。
  8. Stop the MySQL server, then restart it in normal mode again. 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.
  9. 停止MySQL服务器,然后再次以正常模式重启。如果您将服务器作为服务运行,请从Windows Services窗口启动它。如果您手动启动服务器,请使用您通常使用的任何命令。

You should now be able to connect to MySQL as root using the new password.

现在应该可以使用新的密码以root身份连接到MySQL了。

#3


32  

An improvement to the most useful answer here:

对最有用的答案的改进:

1] No need to restart the mysql server
2] Security concern for a MySQL server connected to a network

对于连接到网络的mysql服务器,不需要重新启动mysql服务器

There is no need to restart the MySQL server.

不需要重新启动MySQL服务器。

use FLUSH PRIVILEGES; after the update mysql.user statement for password change.

使用刷新权限;更新后的mysql。密码更改的用户语句。

The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

FLUSH语句告诉服务器将grant表重新加载到内存中,以便它注意到密码的更改。

The --skip-grant-options enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to

skipg -grant选项允许任何人在没有密码和所有特权的情况下连接。因为这是不安全的,你可能想要

use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.

使用—skipg -grant-表与-skip-network,以防止远程客户端连接。

from: reference: resetting-permissions-generic

来自:参考:resetting-permissions-generic

#4


6  

While you can't directly recover a MySQL password without bruteforcing, there might be another way - if you've used MySQL Workbench to connect to the database, and have saved the credentials to the "vault", you're golden.

虽然您不能直接恢复MySQL密码而不使用bruteforce,但是也可以使用另一种方法—如果您使用MySQL Workbench连接到数据库,并将凭据保存到“vault”中,那么您就很幸运了。

On Windows, the credentials are stored in %APPDATA%\MySQL\Workbench\workbench_user_data.dat - encrypted with CryptProtectData (without any additional entropy). Decrypting is easy peasy:

在Windows上,凭据存储在%APPDATA%\MySQL\ workbench_user_data中。用密码保护数据加密(没有任何附加的熵)。解密是容易peasy:

std::vector<unsigned char> decrypt(BYTE *input, size_t length) {
    DATA_BLOB inblob { length, input };
    DATA_BLOB outblob;

    if (!CryptUnprotectData(&inblob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &outblob)) {
            throw std::runtime_error("Couldn't decrypt");
    }

    std::vector<unsigned char> output(length);
    memcpy(&output[0], outblob.pbData, outblob.cbData);

    return output;
}

Or you can check out this DonationCoder thread for source + executable of a quick-and-dirty implementation.

或者,您可以检查一下这个DonationCoder线程,它是一个快速而肮脏的实现的源代码+可执行文件。

#5


3  

If you have root access to the server where mysql is running you should stop the mysql server using this command

如果您具有对正在运行mysql的服务器的根访问权限,那么应该使用此命令停止mysql服务器

sudo service mysql stop

Now start mysql using this command

现在使用这个命令启动mysql。

sudo /usr/sbin/mysqld --skip-grant-tables  --skip-networking &

Now you can login to mysql using

现在可以使用mysql登录

sudo mysql
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Full instructions can be found here http://www.techmatterz.com/recover-mysql-root-password/

完整的指令可以在这里找到http://www.techmatterz.com/recover-mysql-root-password/

#6


1  

Login MySql from windows cmd using existing user:

使用现有用户从windows cmd登录MySql:

mysql -u username -p
Enter password:****

mysql -u用户名-p输入密码:***

Then run the following command:

然后运行以下命令:

mysql> SELECT * FROM mysql.user;

After that copy encrypted md5 password for corresponding user and there are several online password decrypted application available in web. Using this decrypt password and use this for login in next time. or update user password using flowing command:

在复制了相应用户的加密md5密码后,web上可以使用几个在线密码解密应用程序。使用这个解密密码,下次登录时使用这个密码。或使用流畅命令更新用户密码:

mysql> UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';

Then login using the new password and user.

然后使用新的密码和用户登录。

#7


0  

Although a strict, logical, computer science'ish interpretation of the op's question would be to require both "How do I retrieve my MySQL username" and "password" - I thought It might be useful to someone to also address the OR interpretation. In other words ...

尽管对op的问题有严格的、逻辑性的、计算机科学的解释,但它要求“我如何检索我的MySQL用户名”和“密码”——我认为它可能对某些人来说是有用的,也可以处理或解释。换句话说……

1) How do I retrieve my MySQL username?

1)如何检索我的MySQL用户名?

OR

2) password

2)密码

This latter condition seems to have been amply addressed already so I won't bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.

后一种情况似乎已经得到了充分的解决,所以我不会为此费心。下面的解决方案是“如何仅保留我的MySQL用户名”。因HIH。公司破产引发

To find your mysql username run the following commands from the mysql shell ...

要找到您的mysql用户名,请运行以下命令从mysql shell…

SELECT User FROM mysql.user;

从mysql.user选择用户;

it will print a table of all mysql users.

它将打印所有mysql用户的表。

#8


0  

IF you happen to have ODBC set up, you can get the password from the ODBC config file. This is in /etc/odbc.ini for Linux and in the Software/ODBC folder in the registry in Windows (there are several - it may take some hunting)

如果您碰巧安装了ODBC,您可以从ODBC配置文件中获取密码。这是在/etc/odbc.Linux的ini和Windows注册表中的Software/ODBC文件夹(有几个-可能需要一些搜索)

#9


0  

Do it without down time

Run following command in the Terminal to connect to the DBMS (you need root access):

在终端运行以下命令连接到DBMS(需要根访问):

sudo mysql -u root -p;

run update password of the target user (for my example username is mousavi and it's password must be 123456):

运行目标用户的更新密码(我的示例用户名为mousavi,密码必须为123456):

UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE user='mousavi';  

at this point you need to do a flush to apply changes:

此时,您需要做一个刷新来应用更改:

FLUSH PRIVILEGES;

Done! You did it without any stop or restart mysql service.

完成了!没有任何停止或重新启动mysql服务。