How do I change the MySQL root password and username in ubuntu server? Do I need to stop the mysql service before setting any changes?
I have a phpmyadmin setup as well, will phpmyadmin get updated automatically?
Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.
sudo /etc/init.d/mysql stop
mysqld
configuration: sudo mysqld --skip-grant-tables &
In some cases, you've to create the /var/run/mysqld
first:
sudo mkdir -v /var/run/mysqld && sudo chown mysql /var/run/mysqld
mysql -u root mysql
YOURNEWPASSWORD
with your new password:For MySQL < 8.0
UPDATE
mysql.user
SET
Password = PASSWORD('YOURNEWPASSWORD')
WHERE
User = 'root';
FLUSH PRIVILEGES;
exit;
Note: on some versions, if
password
column doesn't exist, you may want to try:UPDATE user SET authentication_string=password('YOURNEWPASSWORD') WHERE user='root';
Note: This method is not regarded as the most secure way of resetting the password, however, it works.
For MySQL >= 8.0
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD';
References:
The only method that worked for me is the one described here (I am running ubuntu 14.04). For the sake of clarity, these are the steps I followed:
sudo vim /etc/mysql/my.cnf
Add the following lines at the end:
[mysqld] skip-grant-tables
sudo service mysql restart
mysql -u root
use mysql
select * from mysql.user where user = 'root';
- Look at the top to determine whether the password column is called
password or authentication_string
UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost';
- Use the proper password column from above
FLUSH PRIVILEGES;
exit
sudo vim /etc/mysql/my.cnf
Remove the lines added in step 2 if you want to keep your security standards.
sudo service mysql restart
For reference : https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With