I have installed mysql 5.7 on a Red Hat Enterprise Linux 5.5 server and when I tried to run following command after installation it is asking for a password for root@localhost.
/usr/bin/mysql_secure_installation
I have never set a root password and I'm logged in to Linux as root user.
Then I have found following documentation for resetting root password and followed that one too.
https://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html
But even after starting the server with following command it is asking for a password
/etc/init.d/mysqld start --skip-grant-tables &
I have tried starting the server with init-file
option, but no success.
Does anyone know how to reset the password correctly or default MySQL password?
-
See the section Recover MySQL root password. I used it yesterday on CentOS 7.user141074– user1410742017年12月22日 14:03:02 +00:00Commented Dec 22, 2017 at 14:03
2 Answers 2
Restart the service without authentication
Ubuntu/Debian
service mysql stop
service mysql start --skip-grant-tables --skip-networking
Other sysv
If you're on a sysv
Linux use this
/etc/init.d/mysqld stop
/etc/init.d/mysqld start --skip-grant-tables --skip-networking &
Resetting
Then you need to login as root
mysql -u root -p
Then when logged in run
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Difference between other guides
There are a lot of "guides" on this, for clarity,
- Some guides use the older
SET PASSWORD
syntax, that's pre 5-7.6, don't use that anymore. - Some guides just don't use
--skip-networking
, that's unsafe. - Some guides don't connect with the
-u root
that's more error-prone.
-
This gives the error:
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
Anadi Misra– Anadi Misra2020年04月15日 13:06:40 +00:00Commented Apr 15, 2020 at 13:06
You can do this, if you want a full clean installation. Resets accounts, too.
sudo apt purge mariadb-server && sudo rm -rf /var/lib/mysql/ && sudo apt install mariadb-server && sudo systemctl stop mariadb && sudo mysql_install_db && sudo systemctl stop mysql && sudo systemctl start mariadb && sudo systemctl enable mariadb
Explore related questions
See similar questions with these tags.