How do I find out my root MySQL password?

前端 未结 11 1994
不知归路
不知归路 2020-12-22 17:39

I just installed MySQL on Ubuntu and the root user can\'t log in :)

How can I recover or find out my password? Using blank for password does not work.

11条回答
  •  不知归路
    2020-12-22 17:53

    MySQL 5.5 on Ubuntu 14.04 required slightly different commands as recommended here. In a nutshell:

    sudo /etc/init.d/mysql stop
    sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
    mysql -u root
    

    And then from the MySQL prompt

    FLUSH PRIVILEGES;
    SET PASSWORD FOR root@'localhost' = PASSWORD('password');
    UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
    FLUSH PRIVILEGES;
    

    And the cited source offers an alternate method as well.

提交回复
热议问题