如何找到MySQL根密码?

时间:2022-04-04 22:13:18

I cannot figure out my MySQL root password; how can I find this out? Is there any file where this password is stored?

我不知道我的MySQL根密码;我怎么才能知道呢?是否有存储此密码的文件?

I am following this link but I do not have directadmin directory in local.

我正在跟踪这个链接,但是我在本地没有directadmin目录。

14 个解决方案

#1


97  

thanks to @thusharaK I could reset the root password without knowing the old password.

感谢@thusharaK,我可以在不知道旧密码的情况下重新设置根密码。

On ubuntu I did the following:

我在ubuntu上做了如下工作:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

then run mysql in a new terminal

然后在一个新的终端运行mysql。

mysql -u root

and run the following query, after changing the password

并在更改密码后运行以下查询。

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

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

在MySQL 5.7中,MySQL的密码字段。用户表字段被删除,现在字段名是“authentication_string”。

quit the mysql safe mode and start mysql service by

退出mysql安全模式,启动mysql服务。

mysqladmin shutdown
sudo service mysql start

#2


57  

You can't view the hashed password; the only thing you can do is reset it!

您不能查看散列密码;你唯一能做的就是重置它!

Stop MySQL:

停止MySQL:

sudo service mysql stop

or

$ sudo /usr/local/mysql/support-files/mysql.server stop

Start it in safe mode:

安全模式启动:

$ sudo mysqld_safe --skip-grant-tables

(above line is the whole command)

(以上是整个命令)

This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:

这将是一个持续的命令,直到进程完成,所以打开另一个shell/终端窗口,登录时没有密码:

$ mysql -u root

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

MySQL 5.7 and over:

MySQL 5.7及以上:

mysql> use mysql; 
mysql> update user set authentication_string=password('password') where user='root'; 

Start MySQL:

MySQL开始:

sudo mysql start

or

sudo /usr/local/mysql/support-files/mysql.server start

Your new password is 'password'.

你的新密码是“密码”。

#3


26  

MySQL 5.7 and above saves root in MySQL log file.

MySQL 5.7和以上在MySQL日志文件中保存根。

Please try this:

请试试这个:

sudo grep 'temporary password' /var/log/mysqld.log

#4


14  

You cannot find it. It is stored in a database, which you need the root password to access, and even if you did get access somehow, it is hashed with a one-way hash. You can reset it: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

你不能找到它。它存储在一个数据库中,您需要root密码才能访问它,即使您确实获得了访问权限,也会使用单向散列进行散列。您可以重置它:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html。

#5


8  

Follow these steps to reset password in Windows system

按照以下步骤在Windows系统中重新设置密码。

  1. Stop Mysql service from task manager

    停止来自任务管理器的Mysql服务。

  2. Create a text file and paste the below statement

    创建一个文本文件并粘贴下面的语句。

MySQL 5.7.5 and earlier:

MySQL 5.7.5:早些时候,

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');

设置“root”@“localhost”=密码(“yournewpassword”);


MySQL 5.7.6 and later:

MySQL 5.7.6和后:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'yournewpassword';

通过“您的新密码”来修改用户的“根”@“localhost”;

  1. Save as mysql-init.txt and place it in 'C' drive.

    存mysql-init。把它放在“C”驱动器上。

  2. Open command prompt and paste the following

    打开命令提示符并粘贴以下内容。

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

C:\ > mysqld——init文件= C:\ \ mysql-init.txt

#6


7  

Unless the package manager requests you to type the root password during installation, the default root password is the empty string. To connect to freshly installed server, type:

除非包管理器请求您在安装期间输入根密码,否则默认根密码是空字符串。要连接到新安装的服务器,请键入:

shell> mysql -u root --password=
mysql>

To change the password, get back the unix shell and type:

要更改密码,请返回unix shell并键入:

shell> mysqladmin -u root --password= password root

The new password is 'root'. Now connect to the server:

新密码是“root”。现在连接到服务器:

shell> mysql -u root --password=
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Oops, the password has changed. Use the new one, root:

噢,密码变了。使用新的,root:

shell> mysql -u root --password=root
...
blah, blah, blah : mysql welcome banner
...
mysql> 

Bingo! New do something interesting

宾果!新做一些有趣的事情

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

Maurycy

Maurycy

#7


4  

The default password which worked for me after immediate installation of mysql server is : "mysql" (without quotes)

mysql服务器直接安装后为我工作的默认密码是:“mysql”(没有引号)

#8


4  

As addition to the other answers, in a cpanel installation, the mysql root password is stored in a file named /root/.my.cnf. (and the cpanel service resets it back on change, so the other answers here won't help)

除其他答案外,在cpanel安装中,mysql根密码存储在名为/root/.my.cnf的文件中。(cpanel服务将其重新设置为更改,因此这里的其他答案也不会有帮助)

#9


3  

In your "hostname".err file inside the data folder MySQL works on, try to look for a string that starts with:

在你的“主机名”。在MySQL工作的数据文件夹中,尝试查找以以下方式开始的字符串:

"A temporary password is generated for roor@localhost "

“为roor@localhost生成临时密码”

you can use

您可以使用

less /mysql/data/dir/hostname.err 

then slash command followed by the string you wish to look for

然后斜杠命令,然后是您希望查找的字符串。

/"A temporary password"

Then press n, to go to the Next result.

然后按n,进入下一个结果。

#10


3  

you can view mysql root password , well i have tried it on mysql 5.5 so do not know about other new version well work or not

你可以查看mysql的根密码,我已经在mysql 5.5上试过了,所以不知道其他的新版本是否有效。

nano ~/.my.cnf

#11


2  

The procedure changes depending the version of MySql. Follow the procedure exactly as described for your version:

程序的变化取决于MySql的版本。按照您的版本所描述的步骤:

  • HINTS - Read before the instructions page for your version of MySql*

    提示-在你的MySql*版本的说明页面之前阅读。

  • In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator".

    在第5步:不要运行CMD,在你的桌面上创建一个快捷方式调用CDM.exe。然后右键单击快捷方式并选择“作为管理员执行”。

  • In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter

    在步骤6中:跳过第一个提议的命令版本,然后执行第二个命令,其中一个是default -file参数。

  • Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager.

    一旦执行了命令,如果一切正常,CMD窗口将保持打开,第6步的命令将继续执行。只需关闭窗口(单击“x”),然后从任务管理器强制关闭MySQl。

  • Delete the file with the SQL commands, and start again MySQL. The password must be changed now.

    使用SQL命令删除文件,然后重新启动MySQL。现在必须更改密码。

5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

... just change the version in the link (5.5, 5.6, 5.7)

…只需更改链接中的版本(5.5,5.6,5.7)

#12


0  

This worked for me:

这工作对我来说:

On terminal type the following

在终端类型上。

$ sudo mysql -u root -p

$ sudo mysql -u root -p。

Enter password://just press enter

输入密码:/ /只是按回车

mysql>

mysql >

#13


0  

You can change your password or if you use Linux, you can use encrypted password. I think this is much more comfortable and secure method than each time changing password.

您可以更改您的密码,或者如果您使用Linux,您可以使用加密的密码。我认为这比每次修改密码要安全得多。

You need of course root privileges and use the following command

当然,您需要root权限,并使用以下命令。

cat /etc/psa/.psa.shadow

Above command will display encrypted password which you can use to log into Mysql as root. Below you can find my often used solution.

上面的命令将显示加密的密码,您可以使用它以root身份登录到Mysql。下面你可以找到我常用的解决方案。

mysql -uadmin -p`cat /etc/psa/.psa.shadow`

#14


-3  

Go to phpMyAdmin > config.inc.php > $cfg['Servers'][$i]['password'] = '';

进入phpMyAdmin > config.inc。php > $cfg['Servers'][$i]['password'] = ";

#1


97  

thanks to @thusharaK I could reset the root password without knowing the old password.

感谢@thusharaK,我可以在不知道旧密码的情况下重新设置根密码。

On ubuntu I did the following:

我在ubuntu上做了如下工作:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking

then run mysql in a new terminal

然后在一个新的终端运行mysql。

mysql -u root

and run the following query, after changing the password

并在更改密码后运行以下查询。

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

In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.

在MySQL 5.7中,MySQL的密码字段。用户表字段被删除,现在字段名是“authentication_string”。

quit the mysql safe mode and start mysql service by

退出mysql安全模式,启动mysql服务。

mysqladmin shutdown
sudo service mysql start

#2


57  

You can't view the hashed password; the only thing you can do is reset it!

您不能查看散列密码;你唯一能做的就是重置它!

Stop MySQL:

停止MySQL:

sudo service mysql stop

or

$ sudo /usr/local/mysql/support-files/mysql.server stop

Start it in safe mode:

安全模式启动:

$ sudo mysqld_safe --skip-grant-tables

(above line is the whole command)

(以上是整个命令)

This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:

这将是一个持续的命令,直到进程完成,所以打开另一个shell/终端窗口,登录时没有密码:

$ mysql -u root

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

MySQL 5.7 and over:

MySQL 5.7及以上:

mysql> use mysql; 
mysql> update user set authentication_string=password('password') where user='root'; 

Start MySQL:

MySQL开始:

sudo mysql start

or

sudo /usr/local/mysql/support-files/mysql.server start

Your new password is 'password'.

你的新密码是“密码”。

#3


26  

MySQL 5.7 and above saves root in MySQL log file.

MySQL 5.7和以上在MySQL日志文件中保存根。

Please try this:

请试试这个:

sudo grep 'temporary password' /var/log/mysqld.log

#4


14  

You cannot find it. It is stored in a database, which you need the root password to access, and even if you did get access somehow, it is hashed with a one-way hash. You can reset it: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

你不能找到它。它存储在一个数据库中,您需要root密码才能访问它,即使您确实获得了访问权限,也会使用单向散列进行散列。您可以重置它:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html。

#5


8  

Follow these steps to reset password in Windows system

按照以下步骤在Windows系统中重新设置密码。

  1. Stop Mysql service from task manager

    停止来自任务管理器的Mysql服务。

  2. Create a text file and paste the below statement

    创建一个文本文件并粘贴下面的语句。

MySQL 5.7.5 and earlier:

MySQL 5.7.5:早些时候,

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yournewpassword');

设置“root”@“localhost”=密码(“yournewpassword”);


MySQL 5.7.6 and later:

MySQL 5.7.6和后:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'yournewpassword';

通过“您的新密码”来修改用户的“根”@“localhost”;

  1. Save as mysql-init.txt and place it in 'C' drive.

    存mysql-init。把它放在“C”驱动器上。

  2. Open command prompt and paste the following

    打开命令提示符并粘贴以下内容。

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

C:\ > mysqld——init文件= C:\ \ mysql-init.txt

#6


7  

Unless the package manager requests you to type the root password during installation, the default root password is the empty string. To connect to freshly installed server, type:

除非包管理器请求您在安装期间输入根密码,否则默认根密码是空字符串。要连接到新安装的服务器,请键入:

shell> mysql -u root --password=
mysql>

To change the password, get back the unix shell and type:

要更改密码,请返回unix shell并键入:

shell> mysqladmin -u root --password= password root

The new password is 'root'. Now connect to the server:

新密码是“root”。现在连接到服务器:

shell> mysql -u root --password=
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Oops, the password has changed. Use the new one, root:

噢,密码变了。使用新的,root:

shell> mysql -u root --password=root
...
blah, blah, blah : mysql welcome banner
...
mysql> 

Bingo! New do something interesting

宾果!新做一些有趣的事情

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

Maurycy

Maurycy

#7


4  

The default password which worked for me after immediate installation of mysql server is : "mysql" (without quotes)

mysql服务器直接安装后为我工作的默认密码是:“mysql”(没有引号)

#8


4  

As addition to the other answers, in a cpanel installation, the mysql root password is stored in a file named /root/.my.cnf. (and the cpanel service resets it back on change, so the other answers here won't help)

除其他答案外,在cpanel安装中,mysql根密码存储在名为/root/.my.cnf的文件中。(cpanel服务将其重新设置为更改,因此这里的其他答案也不会有帮助)

#9


3  

In your "hostname".err file inside the data folder MySQL works on, try to look for a string that starts with:

在你的“主机名”。在MySQL工作的数据文件夹中,尝试查找以以下方式开始的字符串:

"A temporary password is generated for roor@localhost "

“为roor@localhost生成临时密码”

you can use

您可以使用

less /mysql/data/dir/hostname.err 

then slash command followed by the string you wish to look for

然后斜杠命令,然后是您希望查找的字符串。

/"A temporary password"

Then press n, to go to the Next result.

然后按n,进入下一个结果。

#10


3  

you can view mysql root password , well i have tried it on mysql 5.5 so do not know about other new version well work or not

你可以查看mysql的根密码,我已经在mysql 5.5上试过了,所以不知道其他的新版本是否有效。

nano ~/.my.cnf

#11


2  

The procedure changes depending the version of MySql. Follow the procedure exactly as described for your version:

程序的变化取决于MySql的版本。按照您的版本所描述的步骤:

  • HINTS - Read before the instructions page for your version of MySql*

    提示-在你的MySql*版本的说明页面之前阅读。

  • In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator".

    在第5步:不要运行CMD,在你的桌面上创建一个快捷方式调用CDM.exe。然后右键单击快捷方式并选择“作为管理员执行”。

  • In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter

    在步骤6中:跳过第一个提议的命令版本,然后执行第二个命令,其中一个是default -file参数。

  • Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager.

    一旦执行了命令,如果一切正常,CMD窗口将保持打开,第6步的命令将继续执行。只需关闭窗口(单击“x”),然后从任务管理器强制关闭MySQl。

  • Delete the file with the SQL commands, and start again MySQL. The password must be changed now.

    使用SQL命令删除文件,然后重新启动MySQL。现在必须更改密码。

5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

5.0 http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

5.1 http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html

... just change the version in the link (5.5, 5.6, 5.7)

…只需更改链接中的版本(5.5,5.6,5.7)

#12


0  

This worked for me:

这工作对我来说:

On terminal type the following

在终端类型上。

$ sudo mysql -u root -p

$ sudo mysql -u root -p。

Enter password://just press enter

输入密码:/ /只是按回车

mysql>

mysql >

#13


0  

You can change your password or if you use Linux, you can use encrypted password. I think this is much more comfortable and secure method than each time changing password.

您可以更改您的密码,或者如果您使用Linux,您可以使用加密的密码。我认为这比每次修改密码要安全得多。

You need of course root privileges and use the following command

当然,您需要root权限,并使用以下命令。

cat /etc/psa/.psa.shadow

Above command will display encrypted password which you can use to log into Mysql as root. Below you can find my often used solution.

上面的命令将显示加密的密码,您可以使用它以root身份登录到Mysql。下面你可以找到我常用的解决方案。

mysql -uadmin -p`cat /etc/psa/.psa.shadow`

#14


-3  

Go to phpMyAdmin > config.inc.php > $cfg['Servers'][$i]['password'] = '';

进入phpMyAdmin > config.inc。php > $cfg['Servers'][$i]['password'] = ";