大网数据广告活动
服务器运维问答

Made a typo and forgot to close quotes while entering new MySQL root password

· 52CE 我爱测

When entering a new password for the root account in MySQL I accidentally did this: mysqladmin -u root -p password 'somepassword Where you can see I missed the second quote. and I got something like this . > So I entered ' to fin…

问题原文

原帖链接 · CJONES · CC BY-SA 4.0

When entering a new password for the root account in MySQL I accidentally did this:

mysqladmin -u root -p password 'somepassword 

Where you can see I missed the second quote. and I got something like this .

>

So I entered ' to finish the statement and now the password doesn't work.

I'm not asking how to reset or recover the password (I know how to do that but I'm trying to avoid restarting the service). The question is: Is possible or not to enter a password here if this kind of typo is made.

I understand I can start the MySQL server with an init file and reset the password but I was wondering if anyone knows what the above translates to. Is it a new line? Is it possible to manually enter that?

已采纳解答

原帖链接 · Giacomo1968 · CC BY-SA 3.0

Then just reset your MySQL password. This is how I do it in Ubuntu 12.04. Should work similarly in other setups. It’s considered an insecure way of reseting a MySQL password since you do have to launch MySQL in an open/non-credential based mode to do this. But if you do it & then restart MySQL normally, you should be fine.

First, I stop the MySQL service:

sudo service mysql stop

Then I restart it with the --skip-grant-tables flag:

sudo mysqld --skip-grant-tables &

Now you can login without a password like so:

mysql -u root mysql

And then I run the following query to reset the password. Note you should change the value of YOURNEWPASSWORD to whatever password you actually want to use:

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE user='root'; FLUSH PRIVILEGES; exit;

Now that that is done, exit out of MySQL and restart the daemon like so:

sudo service mysql restart

If somehow that doesn’t work, use a killall to kill all instances of mysqld:

killall mysqld

And then start the MySQL service again as you normally would:

sudo service mysql start

The new password should be set & you’re good to go.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-03-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。