如何将MySQL根密码更改为默认密码? [英] How to change MySQL root password to default?
问题描述
我的 MySQL 初始安装没有root用户密码.我为root分配了密码,一切正常.由于某种原因(不要问为什么),我不得不恢复到root没有密码的原始设置.
My initial installation for the MySQL had no password for root. I assigned a password for root and everything worked fine. Due to some reason (don't ask why) I had to revert back to the original settings where root didn't have any password.
我将root密码更改为'' (empty string)
.现在的问题是MySQL不能与'mysql -uroot'
一起运行,它需要一个密码.在运行'mysql -uroot -p'
并在密码提示符下按Enter键后,我进入数据库,但与默认设置不同.
I changed the root password to '' (empty string)
. The problem now is that MySQL doesn't run with 'mysql -uroot'
, it expects a password. On running 'mysql -uroot -p'
and hitting enter on the password prompt gets me into the db, but is not same as the default setting.
设置/取消设置时是否还有其他标记/设置丢失,告诉mysql不希望输入密码?
Is there any other flag/setting that I am missing to set/unset which tells mysql to not expect a password?
谢谢
推荐答案
如何重置MySQL根密码:
要重置它,请参见如何重置根密码在MySQL手册中.
To reset it, see How to Reset the Root Password in the MySQL manual.
如何在没有密码控制的访问权限的情况下运行MySQL
要在禁用密码控制的情况下运行MySQL,请查看-skip-grant-tables 选项.
To run MySQL with the password controls disabled, check out the --skip-grant-tables option.
如何避免在命令行上输入凭据
如果只是想避免在mysql命令行上键入密码,请在主目录中创建一个名为.my.cnf的文件(注意该文件名的前导句号!).对于您的情况,对于root用户,可能是/root
If you simply want to avoid having to type the password on the mysql command line, create a file called .my.cnf (note leading period on that filename!) in your home directory. In your case, for the root user, probably /root
将以下条目添加到文件中
Add the following entries to the file
[client]
host=localhost
user = root
password = mypassword
database = mydatabase
您通常会将此文件更改为chmod 600,以便只有您可以看到它,而MySQL会忽略一个始终可以在世界范围内写入的.my.cnf.
You'd typically chmod 600 this file so that only you can see it, and MySQL will ignore a .my.cnf which is world writable anyway.
请参见手册页使用选项文件更多信息
这篇关于如何将MySQL根密码更改为默认密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!