MySQL is a very popular database management software which allows you to store, modify, delete and design databases along with their data in an organized manner. It has a free and open-source version, known as MySQL community edition licensed under GNU. There are more than enough alternatives available to MySQL, but none prove to be of such excellence, thanks to its unparalleled data protection and workflow control. Unfortunately, every good piece of software comes at a cost.
Having already mentioned that the MySQL community edition comes free of charge, there’s still a price to pay, that is, to set it up without all the frustration it tends to bring you. One such issue is the “failed to start mysql community server” error message that pops up on the terminal when trying to start the mysql daemon.
In this article, I’d try my best to give you all the solutions I could come up with, to save you from bumping your head off!
Why did mysql community server fail to start?
No directory present for log files
There could be several reasons for this, being each a distinction of its own. The most commonly reported issue is the absence of a log folder for mysql. It is also possible that this directory exists, but the user under which you’re trying to run the mysql server does not have the permission to write to the folder.
Configuration file not present or is named wrong
Other than that, there are other possibilities like the wrong name for the configuration file of mysql, or not having the file at all. When the server starts, it needs to scan the configuration file. So if you don’t have that file in the right directory, then you’d be unable to run the mysql server.
Not starting server as root user
Nonetheless, if you feel like that’s all, you’d definitely be wrong. Other cases include not running the server as the root user. You cannot start or stop any services in a Linux machine as long as you’re not logged in as the root user, or your current user does not have administrative privileges.
There are several fixes available for you to eradicate this one heck of an error message. If your luck turns out well, at least one among the first few mentioned fixes should get your job done. But if it isn’t so, then you might as well need to go through each of the fixes one by one to see if it has worked for you.
Unfortunately, server errors like these have no single answer as to why you may see the error message. Different users face it in different ways. So try not to lose patience if it is taking more time than you’d expect! Let’s get started, comrades!
How to fix ‘Failed to start MySQL community server’
Restart the server (if applicable)
The first thing you should consider doing before trying out any other techniques is to first see if you can restart the server. In many cases, simply restarting the server may be enough to fix your problem. To do this, execute the following commands:
$ sudo systemctl stop mysqld
$ sudo systemctl disable mysqld
$ sudo systemctl mysqld
Make sure you don’t mess up on the name of the server here. It would be mysqld, instead of mysql, as it’s daemon.
Start the server as root
Yes. This one is also a very applicable solution that could work out for many of you, that is, to start the server as root if you aren’t doing that already. Only the root users and those who have been granted administrative privileges can start, stop, enable or disable a service or daemon. Also, it is a good idea to see if the service starts if you actually log in as the root user, instead of just using the sudo command.
Create the log directory
A log directory is extremely essential for a server application like MySQL to run. if you don’t have this directory, then the server will not be able to start. So to fix, this, create the directory by using:
$ sudo mkdir -p /var/log/mysql/
Make sure to run the command as root or by using the sudo command.
In a few other circumstances, another directory called mysql-files under the /var/lib/ directory may not exist in your machine. It should be created automatically when installing the mysql server, but if it doesn’t for some reason, then mysql will be unable to start. To fix this issue as well, simply create the directory:
$ sudo mkdir -p /var/lib/mysql-files
If this directory already exists, then your terminal will return you an output like:
“mkdir: cannot create directory ‘mysql-files’: File exists”
Change permissions for the log directory
Once you’ve created the directories mentioned in the previous section, you also need to make sure that your user can access those directories. To give your user (other than root) the permission to access these directories, run the following command:
$ sudo chown <username> /var/log/mysql/
And if you’ve created the mysql-files directory, then execute this command as well:
$ sudo chown <username> /var/lib/mysql-files
In both the above lines of command, make sure to replace <username> with the actual name of your user.
Check if port 3306 is busy
For certain users, the default port for the mysql server may already be occupied by other programs. While this is quite unlikely, as mysql uses a very distinctive port number, you might still be facing this problem. To fix this, you first need to figure out which program is actually occupying the port, by running this command:
$ netstat -an | grep -i listen | grep -E 3306
This command will return you with the name of the program, or if there’s no program occupying it in the first place, then no output will be returned.
If you’ve found the name for the program, then stop that program’s service by running:
$ sudo systemctl stop <program_name>
$ sudo systemctl disable <program_name>
Make sure you replace the <program_name> with the actual name of the program. Once you’re done stopping the program, now try running the mysql server once again:
$ sudo systemctl start mysqld
These fixes should help you out in diminishing the error message that you face regarding the mysql community server. If none of the fixes have worked for you, there are two things left that you might consider. The first is to diagnose the error message by looking at the files that’d be created in the log directory of mysql (if the directory exists). Inside these log files, the actual problems of the issue are mentioned.
Other than that, if it is not your job that is requiring the mysql server, or if your particular project can work with any other server applications similar to mysql, you might as well consider a few alternatives, just in case.
Alternatives to MySQL community server
Among the many available alternatives mysql, one of the most popular alternatives that many companies actually use themselves are:
Beside these 3 top alternatives, there is also the Microsoft SQL Server, which is also a good alternative that you can consider. But beware, it comes at quite a cost. The free edition is good enough for most, but disheartening.
I’m fairly hopeful that you’ve successfully been able to surpass the error message of the mysql community server. As it will not be possible to bring up every possible issue regarding the error message, there might be instances where you need to work out the solution yourself. But luckily, all the statements that are provided in the log files are very clear about where the problem is emerging from. Therefore, fixing the error should not be too hard if the ones mentioned here don’t work for you. What you’ll mostly need to do, is to access the log files that are created when attempting to run the mysql server.