How to change the mysql root password

后端 未结 10 1428
误落风尘
误落风尘 2020-11-30 08:56

I have installed MySQL server 5 on redhat linux. I can\'t login as root so I can\'t change the root password.

mysql -u root -p  
Enter password:  

        
相关标签:
10条回答
  • 2020-11-30 09:24

    One option is to save UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root'; into a file and then manually start mysqld with --init-file=FILENAME. Once the server starts, it should reset your password, and then you should be able to log in. After this, you should shut down the server and start it normally.

    0 讨论(0)
  • 2020-11-30 09:26

    Remove the -p from your command. -p forces the prompt for password.

    Use : mysql -u root

    This will resolve your problem.

    0 讨论(0)
  • 2020-11-30 09:28

    According to the docs, in MySQL 5.7 the temp password gets put in /var/log/mysqld, but this is evidently not the case in 5.6.

    With MySQL version 5.6 installed on RHEL 6.7, I finally found the temporary root password set during install was placed in the file /root/.mysql_secret.

    0 讨论(0)
  • 2020-11-30 09:30

    A little late to the game, but I had the same issue on a raspberry pi install and found out that it needs elevation. Adding a sudo to the front of the password change allowed it to work.

    sudo mysqladmin -u root password 'newpass'
    

    followed by an elevated sql access

    sudo mysql -u root -p  
    

    If either are not run as sudo, it will fail.

    0 讨论(0)
提交回复
热议问题