How to change the MySQL root account password on CentOS7?

前端 未结 7 751
故里飘歌
故里飘歌 2020-12-12 08:58

I have installed mySQL on a Centos7 vm but I have problems logging in with root. I tried logging in without password or tried any default ones (like mysql, admin etc) I look

7条回答
  •  遥遥无期
    2020-12-12 09:24

    All,

    Here a little bit twist with mysql-community-server 5.7 I share some steps, how to reset mysql5.7 root password or set password. it will work centos7 and RHEL7 as well.

    step1. 1st stop your databases

    service mysqld stop

    step2. 2nd modify /etc/my.cnf file add "skip-grant-tables"

    vi /etc/my.cnf
    

    [mysqld] skip-grant-tables

    step3. 3rd start mysql

    service mysqld start

    step4. select mysql default database

    mysql -u root
    
    mysql>use mysql;
    

    step4. set a new password

    mysql> update user set authentication_string=PASSWORD("yourpassword") where User='root';

    step5 restart mysql database

    service mysqld restart
    
     mysql -u root -p
    

    enjoy :)

提交回复
热议问题