Mysql: change root password

I mistakenly pressed

<delete from mysql.user where password =''>

      

Sorry, the password for the user is ''.

When I try to use mysqladmin I get a message that I cannot set a password for

<root @ localhost>

      

Any ideas ???

Many thanks

+3


source to share


4 answers


If you are using a Unix-like OS:

  • You need to kill the mysql daemon.
  • Create a text file and write:
UPDATE mysql.user SET Password=PASSWORD('YOUR_PASSWORD') WHERE User='root';

      



FLUSH PRIVILEGES;

  • Open a console and enter "mysqld_safe --init-file = YOUR_FILE &"
  • Reboot the server
  • You should now be able to work.
+1


source


run the following command:



mysqladmin -u root -p'oldpassword' password newpass

      

0


source


If you do not have a root password, you can simply connect without the "-p" option. Then you can change the password in the "mysql.user" table

0


source


Stop mysqld

and restart it using a parameter --skip-grant-tables

. Then run in mysql shell:

INSERT INTO user
VALUES('localhost','user',PASSWORD('newpass'),
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'','','','',0,0,0,0);

      

Logout and restart mysql normally.

0


source







All Articles