问题原文
原帖链接 · 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
