Восстановление пароля root в MySQL
password repair
mysql
Как сменить root пароль MySQL
- Останавливаем службу MySQL:
/etc/init.d/mysql stop
2. Запускаем службу с опцией --skip-grant-tables
mysqld_safe --skip-grant-tables &
- Подключаемся с серверу MySQL при помощи клиента mysql:
mysql -u root
- Вводим новый пароль для root:
mysql> use mysql;
mysql> update user set password=PASSWORD"NEW\-ROOT\-PASSWORD" where User='root';
mysql> flush privileges;
В Centos 7 можно посмотреть автоматически сгенерированный пароль так:
sudo grep 'temporary password' /var/log/mysqld.log
2019-05-28T13:36:33.142558Z 1 [Note] A temporary password is generated for root@localhost: z,9zk\<x:A0*!
Сброс пароля Centos 7 отличается от традиционного:
https://stackoverflow.com/questions/33510184/change-mysql-root-password-on-centos7
- Stop mysql:
systemctl stop mysqld
- Set the mySQL environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
- Start mysql usig the options you just set
systemctl start mysqld
- Login as root
mysql -u root
- Update the root user password with these mysql commands
mysql> 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';
- Stop mysql
systemctl stop mysqld
- Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS
- Start mysql normally:
systemctl start mysqld
Try to login using your new password:7. mysql -u root -p