Reset MySQL root password if you forgot it #mysql

Just had a need to reset the mysql root login password for a server, did a bit of Googling and found out this is how you do it (I work on Ubuntu so you may have to tinker with the lines slightly depending on your distribution): Stop the current MySQL instance from running: /etc/init.d/mysql stop Run mysql with –skip-grant-tables /usr/bin/mysqld_safe –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/ –socket=/var/run/mysqld/mysqld.sock –port=3306 –skip-grant-tables & Log into mysql, straight into the mysql database mysql -u root mysql Reset the root password. UPDATE user SET Password=PASSWORD(‘newrootpassword’) WHERE User=’root’; Flush privileges flush privileges; Shut down the new running mysql. … Continue reading