How to change the MySQL root account password on CentOS7?

前端 未结 7 750
故里飘歌
故里飘歌 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:17

    For CentOS 7 and MariaDB 10.4, I had success with the following commands:

    su -
    systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --user=mysql"
    systemctl restart mariadb
    mysql -u root
    
    flush privileges;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    flush privileges;
    quit
    
    systemctl unset-environment MYSQLD_OPTS
    systemctl restart mariadb
    

提交回复
热议问题