Reputation: 1665
How do I change the MySQL root password in ubuntu server via a file? The file may be any shell script or normal text file.
My try:
Normally the below command, in the terminal, changes the password for newly installed mysql.
mysqladmin -u root password 'newpass'
But while doing it via file it's showing the bellow error.
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
So can someone help me to do so.
Upvotes: 1
Views: 384
Reputation: 35
sudo mysql -u root
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
FLUSH PRIVILEGES;
EXIT;
test password
mysql -u root -p
sudo systemctl restart mysql
Upvotes: 0
Reputation: 6305
Stop the MySQL Server: sudo /etc/init.d/mysql stop
Start the mysqld configuration: sudo mysqld --skip-grant-tables
Login to MySQL as root: mysql -u root mysql
Replace YOURNEWPASSWORD with your new password:
UPDATE
mysql.user
SET
Password = PASSWORD('YOURNEWPASSWORD')
WHERE
User = 'root';
FLUSH PRIVILEGES;
exit;
Note: This method is not regarded as the most secure way of resetting the password, however, it works.
Upvotes: 1
Reputation: 2372
If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root follow : Resetting Permissions
Upvotes: 0