How to find out the MySQL root password

后端 未结 17 2503
野趣味
野趣味 2020-11-29 15:29

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

I am following this link but I do not have dir

17条回答
  •  孤独总比滥情好
    2020-11-29 16:08

    I solved this a different way, this may be easier for some.

    I did it this way because I tried starting in safe mode but cannot connect with the error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    What I did was to connect normally as root:

    $ sudo mysql -u root
    

    Then I created a new super user:

    mysql> grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;
    mysql> quit
    

    Then log in as myuser

    $ mysql -u myuser -p -h localhost
    

    Trying to change the password gave me no errors but did nothing for me so I dropped and re-created the root user

    mysql> drop user 'root'@'localhost;
    mysql> mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'mypassword' with grant option;
    

    The root user is now working with the new password

提交回复
热议问题