DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Alexey has posted 28 posts at DZone. View Full User Profile

Reset MySQL Password On Ubuntu

06.19.2011
| 5084 views |
  • submit to reddit
        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