MySQL 8 Installation and Root Password Reset Guide
Step-by-step setup for Ubuntu / Debian, Rocky / CentOS / AlmaLinux, and Windows.
What you get: MySQL 8 installation steps, first-time hardening, safe root password reset workflow, and common error troubleshooting.
Who this is for: beginners, solo developers, and small-team operators.
1. Prerequisites
- Administrator access is required (
sudoon Linux or Administrator CMD/PowerShell on Windows). - Make sure system time is correct (important for logs and security behavior).
- For production servers, create a snapshot or backup before password recovery actions.
2. Install MySQL 8 on Ubuntu / Debian
# 1) Update package index sudo apt update # 2) Install MySQL Server sudo apt install -y mysql-server # 3) Enable and start service sudo systemctl enable --now mysql sudo systemctl status mysql --no-pager # 4) Verify version mysql --version
Initial security hardening
sudo mysql_secure_installation
Recommended: remove anonymous users, disable remote root login, remove test database, and reload privilege tables.
3. Install MySQL 8 on Rocky / CentOS / AlmaLinux (Community Edition)
# 1) Install official MySQL repository (EL9 example) sudo dnf install -y https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm # 2) Install MySQL Community Server sudo dnf install -y mysql-community-server # 3) Enable and start service sudo systemctl enable --now mysqld sudo systemctl status mysqld --no-pager # 4) Verify version mysql --version
Read temporary root password and harden installation
# A temporary password is often generated on first install sudo grep 'temporary password' /var/log/mysqld.log # Complete security setup sudo mysql_secure_installation
4. Install MySQL 8 on Windows (MySQL Installer)
- Download and run MySQL Installer (Community edition).
- Select
MySQL Server 8.0.xand proceed with default setup unless you have custom requirements. - Set a strong root password during configuration and keep port
3306if available. - Note your service name (commonly
MySQL80) and set it to auto-start.
5. Linux: Reset Forgotten Root Password (Safe Procedure)
Important: this procedure temporarily bypasses auth checks. Use only in controlled access environments and include --skip-networking.
# 1) Stop service (choose the one used on your system) sudo systemctl stop mysql # or sudo systemctl stop mysqld # 2) Start temporary no-auth mode (local only) sudo mysqld_safe --skip-grant-tables --skip-networking &
# 3) Open a new terminal and connect mysql -u root # 4) Reset root password FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword!123'; # 5) Exit exit;
# 6) Stop temporary process and restart normally sudo pkill -f mysqld_safe sudo systemctl start mysql # or sudo systemctl start mysqld # 7) Verify login mysql -u root -p
6. Windows: Reset Forgotten Root Password
:: 1) Open Administrator CMD and stop MySQL service net stop MySQL80 :: 2) Start server in skip-grant mode (keep this window open) mysqld --console --skip-grant-tables --skip-networking
:: 3) Open a second Administrator CMD window mysql -u root FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword!123'; exit;
:: 4) Close skip-grant console, then restart service net start MySQL80 :: 5) Verify mysql -u root -p
7. Post-Install Best Practices
- Create dedicated application users. Do not run apps with root account.
- Expose database ports only when necessary; prefer private network access.
- Set up regular backups and test restore procedures periodically.
- Document service names, config file paths, and recovery steps for your team.
8. Common Troubleshooting
| Issue | Typical Cause | What to Check |
|---|---|---|
Access denied for user 'root' |
Wrong password, host mismatch, or auth plugin mismatch | Re-run reset flow, then verify root@localhost in user table |
| Cannot connect to port 3306 | Service stopped, firewall blocked, bind-address restrictions | Check service status, firewall rules, and MySQL bind settings |
| Service fails to start | Bad config or data directory permission issues | Inspect system logs and MySQL error logs |
| Installed MariaDB instead of MySQL | Default distro package selected | Switch to official MySQL Community repository |