How to Install MySQL 5.7 on CentOS 7 and Reset the Root Password
This guide walks through installing MySQL Server 5.7 on CentOS 7 via the official RPM repository, explains why the default root login fails, and provides step‑by‑step commands to stop the service, start it with skip‑grant‑tables, update the root password, and restart MySQL for successful login.
Background
MySQL Server 5.7 was installed on a CentOS 7 system using the official MySQL community RPM package ( mysql57-community-release-el7-7.noarch.rpm). After installation, attempting to log in as root failed with
ERROR 1045 (28000): Access denied for user 'root'@'localhost'.
Why the login fails
Starting with MySQL 5.7 the server creates the root account with a random temporary password. The traditional mysqld_safe script is no longer provided, and the user table column password has been renamed to authentication_string. Consequently, the usual password‑reset procedures that modify user.password do not work.
Installation (RPM method)
su root
sudo wget http://repo.mysql.com/mysql57-community-release-el7-7.noarch.rpm
sudo rpm -ivh mysql57-community-release-el7-7.noarch.rpm
sudo yum install mysql-serverKey changes in MySQL 5.7
mysqld_safe has been removed; the RPM package does not install it.
The user table column password is now called authentication_string.
Resetting the root password
Use systemd to start MySQL with grant tables disabled, change the password, then restart the service.
sudo systemctl stop mysqld.service sudo systemctl set-environment MYSQLD_OPTS="--user=mysql --skip-grant-tables --skip-networking" sudo systemctl start mysqld.serviceConnect without authentication: mysql -u root mysql At the MySQL prompt, update the password and flush privileges:
UPDATE mysql.user SET authentication_string=PASSWORD('abcdef') WHERE user='root' AND host='localhost';
FLUSH PRIVILEGES;
QUIT; sudo systemctl unset-environment MYSQLD_OPTS sudo systemctl restart mysqld.serviceAfter these steps the root account can log in using the new password (e.g., abcdef).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
