How to reset the mysql root password

I have installed mySQL on a Centos7 vm but I have sầu problems logging in with root. I tried logging in without password or tried any default ones (like mysql, admin etc) I looked in the my.cnf file and there"s no password. I tried changing the password by stopping the service and restarting it with mysqld_safe --skip-grant-tables và but I get that mysqld_safe:comm& not foundI have sầu no idea what else to lớn bởi vì. Any tips/ideas would be greatly appreciated!



What version of mySQL are you using? I""m using 5.7.10 and had the same problem with logging on as root

There is 2 issues - why can"t I log in as root lớn start with, and why can I not use "mysqld_safe` lớn start mySQL to lớn rephối the root password.

Bạn đang xem: How to reset the mysql root password

I have no answer lớn setting up the root password during installation, but here"s what you bởi vì to lớn rephối the root password

Edit the initial root password on install can be found by running

grep "temporary password" /var/log/mysqld.log

systemd is now used khổng lồ look after mySQL instead of mysqld_safe (which is why you get the -bash: mysqld_safe: commvà not found error - it"s not installed)

The user table structure has changed.

So lớn remix the root password, you still start mySquốc lộ with --skip-grant-tables options & update the user table, but how you vì it has changed.

Xem thêm: Ánh Sáng Trở Về Remix + Lệnh Xóa Sổ, Xem Phim Online Lệnh Xoá Sổ Tron Bo

1. Stop mysql:systemctl stop mysqld2. Set the mySQL environment option systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"3. Start mysql usig the options you just setsystemctl start mysqld4. Login as rootmysql -u root5. Update the root user password with these mysql commandsmysql> UPDATE mysql.user SET authentication_string = PASSWORD("MyNewPassword") -> WHERE User = "root" AND Host = "localhost";mysql> FLUSH PRIVILEGES;mysql> quit*** Edit ***As mentioned my shokulei in the comments, for 5.7.6 and later, you should use mysql> ALTER USER "root"
"localhost" IDENTIFIED BY "MyNewPass";Or you"ll get a warning6. Stop mysqlsystemctl stop mysqld7. Unphối the mySquốc lộ envitroment option so it starts normally next timesystemctl unset-environment MYSQLD_OPTS8. Start mysql normally:systemctl start mysqldTry lớn login using your new password:7. mysql -u root -pReference

As it says at,


As of MySquốc lộ 5.7.6, for MySquốc lộ installation using an RPM distribution, server startup và shutdown is managed by systemd on several Linux platforms. On these platforms, mysqld_safe is no longer installed because it is unnecessary. For more information, see Section 2.5.10, “Managing MySquốc lộ Server with systemd”.

Xem thêm: Hướng Dẫn Cách Nén Nhiều Hình Ảnh Vào 1 File Pdf Trên Windows

Which takes you to lớn where it mentions the systemctl set-environment MYSQLD_OPTS= towards the bottom of the page.

The password rephối commands are at the bottom of

Chuyên mục: Kiến thức Hosting