Casey

Full-Stack Developer

#shell #sql

Reset MySQL Password from CLI

# Stop MySQL Service
sudo systmctl stop mysql

# Make service directory and give permission to mysql to write
sudo mkdir /var/run/mysqld
sudo chown mysqld: /var/run/mysqld

# Start MySQL manually
sudo mysqld_safe --skip-grant-tables --skip-networking &

# Login
mysql -uroot mysql

# Update the password
UPDATE mysql.user SET authentication_string=PASSWORD('NEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';
EXIT;

# Shutdown manual service
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown

# Restart MySQL
sudo systemctl restart mysql