Changing MySQL root password in CLI

5 posts / 0 new
Last post
#1 Wed, 04/24/2013 - 23:30
yngens

Changing MySQL root password in CLI

I know I can change Webmin root password with:

/usr/libexec/webmin/changepass.pl /etc/webmin root

Now I wonder is there any webmin command to change MySQL root password in a command line? I wonder does clicking on Webmin > Servers >MySQL Database Server > Change Administration Password > ... > Change Now trigger any webmin CLI command?

I know there is recommended way of changing MySQL root password on http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

shell> mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
mysql> FLUSH PRIVILEGES;

but I am looking for even nicer and shorter way of updating MySQL root password in a CLI. Oneliner like /usr/libexec/webmin/changepass.pl /etc/webmin root would be just great.

Thu, 04/25/2013 - 08:35
andreychek

Howdy,

There isn't a simpler way on the command line using Virtualmin.

The way you found is the best way to reset the MySQL root password if you no longer have the original password.

Or, if you're just looking to change the MySQL root password, and you still have the original one, you can use the mysqladmin tool to do that.

Something like this can do that:

mysqladmin -u root -p'oldpassword' password newpass

Thu, 04/25/2013 - 14:17 (Reply to #2)
yngens

Hi,

I am looking for easy way of changing MySQL root for multiple copies of the same Cloudmin VPS'. Can't leave the old one for different VPS', at the same time constantly changing it with looking first at the old password is (ok and doable, but) tiresome. The way I found also takes too long, especially when doing it many many times.

So I am starting to think if there is no onliner way of changing the MySQL root password without old password, then maybe there is a file containing the password somewhere, that could be simply removed in CLI, so that every copied VPS system required to set new password? In other words is there easy way to get rid of current (old) password?

Thu, 04/25/2013 - 22:01
andreychek

In other words is there easy way to get rid of current (old) password?

None that I know of, sorry :-)

Wed, 05/28/2014 - 14:03
baobab33

I had issues and could finaly get to change the root password with this :

kill \`cat /var/run/mysqld/mysqld.pid\`
 
mysqld --skip-grant-tables

then

UPDATE mysql.user SET Password=PASSWORD('my-new-password') WHERE User='root';

(of course change "my-new-password" with your own password) stop and restart mysql normaly

/etc/init.d/mysql restart

and that should work now

Topic locked