How do I change the password of the root user in MySQL?,
I have long since forgotten the password for the root user on one of my boxes. Is there a way I can change it without having to log in to the instance, or will I have to reinstall?
shell> /etc/init.d/mysql stop
- without password autentification
- without connection to the network
Access to database is only possible through it’s sock file ‘/var/lib/mysql/mysql.sock’.
shell> mysqld --user=mysql --pid-file=/var/lib/mysql/mysqld.pid --socket=/var/lib/mysql/mysql.sock --datadir=/var/lib/mysql --skip-grant-tables --skip-networking &
Connect to the database and change password:
shell> mysql --database mysql --socket=/var/lib/mysql/mysql.sock
If you want to, show all users:
mysql> select User, password from user;
Set new password:
mysql> update user set password=password('NEW PASS') WHERE User='USERNAME';
Leave database connection:
Restart database server “normally”.
shell> kill `cat /var/lib/mysql/mysqld.pid` shell> /etc/init.d/mysql start
That’s the answer How do I change the password of the root user in MySQL?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you