During the installation of MySQL on Ubuntu 22.04, you may encounter some common errors that can cause disruption. This article will list common errors and how to fix them in a simple and effective way.

First, you need to identify the specific error, such as checking the log file to accurately determine the MySQL issue. Then, combine this with the common errors below to find the correct and effective solution.
1. Error: “E: Unable to locate package mysql-server”
Cause:
- The Ubuntu repository has not been updated.
- The MySQL version is not available in Ubuntu’s default repository.
Solution:
Use the official package repository from Ubuntu:
sudo add-apt-repository universe sudo apt update
After running sudo apt update
, you can install mysql-server
.
2. Error: “E: Package ‘mysql-server’ has no installation candidate”
Cause:
- The MySQL version you want to install is not available in the repository.
- The repository configuration is faulty or not properly added.
Solution:
- Remove the old repository: Check in
/etc/apt/sources.list
or/etc/apt/sources.list.d
and remove everything related to MySQL. - Add the official MySQL repository: Copy and run the commands below in Terminal.
cd ~/Downloads wget https://dev.mysql.com/get/mysql-apt-config_0.8.33-1_all.deb sudo dpkg -i mysql-apt-config_0.8.33-1_all.deb sudo apt update
After that, you can install MySQL with:
sudo apt install mysql-server.
3. Error: “Failed to start MySQL service”
Cause:
- MySQL fails to start due to installation conflicts, missing configuration files, or incorrect permissions.
- If the disk is full and there’s no storage space, MySQL cannot start.
- Any error in a database can stop MySQL.
Solution:
- Check the config file
/etc/mysql/my.cnf
or/etc/mysql/conf.d/mysql.cnf
- Fix the configuration file issue, example:
sudo mv /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
Restart MySQL:
sudo systemctl restart mysql
Note: If you delete my.cnf
or mysql.cnf
and restart MySQL, the system will automatically create a default configuration. If MySQL still doesn’t start, you may need to delete the /var/lib/mysql
directory.
Important: Before deleting /var/lib/mysql
, back up your data.
sudo mv /var/lib/mysql /var/lib/mysql.bak
After deleting /var/lib/mysql
and /etc/mysql/my.cnf
or /etc/mysql/conf.d/mysql.cnf
, please restart the service again.
sudo systemctl restart mysql
4. Error: “Access denied for user ‘root’@’localhost'”
Cause:
- The root account’s access is not set up correctly.
- The MySQL authentication plugin is incompatible (using
unix_socket
instead ofmysql_native_password
).
Solution:
Log in to MySQL:
sudo mysql -u root -p
Reset root privileges:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'; FLUSH PRIVILEGES;
Or:
ALTER USER 'root'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'your_password'; FLUSH PRIVILEGES;
Then restart MySQL.
5. Error: “Cannot connect to MySQL server on ‘localhost’ (10061)”
Cause:
- MySQL is not running or not listening to connections on port 3306.
Solution:
Check service status:
sudo systemctl status mysql
If it’s not running, restart it:
sudo systemctl start mysql
Check MySQL port:
sudo ss -tuln | grep 3306
If port 3306 is not found, check the configuration file:
sudo nano /etc/mysql/my.cnf Or: sudo nano /etc/mysql/conf.d/mysql.cnf
Ensure the [mysqld]
section has the following line: bind-address = 127.0.0.1
Open the firewall port (if remote connection needed):
sudo ufw allow 3306; sudo ufw reload
6. Error: “dpkg was interrupted, you must manually run ‘sudo dpkg –configure -a'”
Cause:
- The previous installation was interrupted.
Solution:
You need to cleanly remove MySQL from the system and reinstall it.
Step 1: Run the following command to automatically fix broken packages:
sudo dpkg --configure -a
Step 2: After completing Step 1, if the issue still persists, and since you are performing a fresh installation of MySQL, it’s best to start by cleaning everything first.
sudo service mysql stop sudo apt purge 'mysql*' mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-* sudo apt remove 'mysql*' && sudo apt autoremove && sudo apt autoclean sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql sudo apt update && sudo apt upgrade -y
Now, you can start reinstalling MySQL or MariaDB.
7. Error: “Could not open file ‘/var/log/mysql/error.log'”
Cause:
- MySQL log file access permissions are incorrect.
Solution:
Check the configuration: The log configuration is usually located in /etc/mysql/my.cnf
or /etc/mysql/conf.d/mysql.cnf
. Find the log configuration directory.
Example log configuration at: /var/log/mysql/error.log
. Make sure the file is owned by mysql
user.
Fix permissions:
sudo chown mysql:mysql /var/log/mysql/error.log sudo chmod 640 /var/log/mysql/error.log
Common errors when installing MySQL on Ubuntu 22.04 may come from system configurations, repositories, or access permissions. Understanding the causes and following the solutions above will help you resolve most issues. If you still encounter errors, check the system logs carefully to pinpoint the exact cause, or seek help from the community. 😊
This article is based on personal experience and various resources you can refer to: