Many developers prefer running MySQL without root password during local development for convenience. This setup eliminates constant password prompts and simplifies testing workflows. While not recommended for production, this approach is common in dev environments.
Method 1: Using mysqladmin
# Stop MySQL service first sudo systemctl stop mysql # Start MySQL without password verification sudo mysqld_safe --skip-grant-tables & # Connect to MySQL mysql -u root # Execute password reset UPDATE mysql.user SET authentication_string='' WHERE User='root'; FLUSH PRIVILEGES; EXIT; # Restart MySQL normally sudo systemctl restart mysql
Method 2: Via Configuration File
1. Edit /etc/mysql/my.cnf (or my.ini on Windows) 2. Add under [mysqld]: skip-grant-tables 3. Restart MySQL: sudo systemctl restart mysql 4. Connect and clear password: mysql -u root ALTER USER 'root'@'localhost' IDENTIFIED BY ''; 5. Remove skip-grant-tables line 6. Restart MySQL again
While convenient, this approach has security implications:
- Only use empty passwords on local development machines
- Never expose MySQL ports to external networks
- Consider using .my.cnf file with credentials instead
Create ~/.my.cnf with these contents:
[client] user=root password=yourpassword
This maintains security while reducing login prompts. Set file permissions to 600.
Authentication plugin problems:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
Permission errors: Ensure you have sudo privileges when stopping/starting MySQL service.
Many developers prefer working with an empty root password in local development environments for convenience. While this practice isn't recommended for production systems, it's a common workflow choice when:
- Testing scripts locally without password prompts
- Running automated tests that require database access
- Working on personal projects with no security concerns
The simplest way to reset to an empty password:
mysqladmin -u root -p'current_password' password ''
Example workflow:
# First stop MySQL service sudo systemctl stop mysql # Start MySQL without password verification sudo mysqld_safe --skip-grant-tables & # Connect to MySQL mysql -u root # Execute password reset UPDATE mysql.user SET authentication_string='' WHERE User='root'; FLUSH PRIVILEGES; exit;
For more control, execute these SQL commands:
ALTER USER 'root'@'localhost' IDENTIFIED BY ''; -- or for older MySQL versions: SET PASSWORD FOR 'root'@'localhost' = '';
After resetting, ensure your my.cnf/my.ini allows empty passwords:
[mysqld] skip-grant-tables # For MySQL 8.0+ default-authentication-plugin=mysql_native_password [client] user=root password=
Remember these important security notes:
- Never use empty passwords on internet-facing servers
- Consider using .my.cnf files for development credentials
- For production, always use strong passwords and proper authentication