Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

mysql root password forgotten

I did not use PHP MySQL for quite a while and now I need to use it again. But the problem is I forget the password for the MySQL console. and getting error #1045 when trying to login in to PHPMyAdmin.

In the MySQL site I saw an article how to reset root password( http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows)

Steps are

create a mysql-init.txt file containing UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';
FLUSH PRIVILEGES;

I saved it as C:memysql-init

and in command prompt I wrote--

C:wampinmysqlmysql5.5.8inmysqld --init-file=C:memysql-init.txt 

I tried with double backslashes also..but it is not working. MySQL console is asking for a password and it's not taking the new-one. What am I doing wrong? I have several tables there.what to do?

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are the steps to be followed:

  1. Locate the MySQL configuration file using: $ mysql --help | grep -A 1 "Default options"

enter image description here

On Ubuntu 16, the file location is typically /etc/mysql/mysql.conf.d/mysqld.cnf

  1. Edit the configuration file using: $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

  2. Add skip-grant-tables under [mysqld] block and save the changes.

enter image description here

  1. Restart MySQL service using: sudo service mysql restart

  2. Check MySQL service status: sudo service mysql status

enter image description here

  1. Login to mysql with: $ mysql -u root

  2. And change the root password:

mysql> FLUSH PRIVILEGES;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';

  1. Revert back the MySQL configuration file changes by removing skip-grant-tables line or commenting it with a # (hash).

  2. Finally restart the MySQL service and you are good to go.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...