Over a million developers have joined DZone.

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


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


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


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}