Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Reset MySQL Password On Ubuntu

DZone's Guide to

Reset MySQL Password On Ubuntu

·
Free Resource
Check if MySQL is running. (display all sockets with TCP protocol, show program name for them)

netstat -tap | grep mysql


Stop MySQL:

sudo stop mysql

or

sudo /etc/init.d/mysql stop


Start MySQL server so that everyone could connect without a password and with all privileges (+ prevent remote clients from connecting for security reasons):

sudo mysqld --skip-grant-tables --skip-networking


In another shell tab connect to MySQL without password

mysql


Update passwords in the MySQL:

mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;


Stop the MySQL server:

sudo mysqladmin shutdown


Start normally:

sudo start mysql


Connect normally:

mysql -u root -p

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}