×


MySQL error log cPanel

Are you facing any MySQL error and would like to view the error log in CPanel to find the reason for it?

This guide is for you.


An error log is a personalized document that lists your mistakes and how to correct them. 

When you receive feedback about a mistake in your writing, you create an entry in your error log that includes the error and how to correct it.

MySQL error logs provide the exact reason behind any MySQL error. 

Referring to this, we can fix any MySQL errors in the server.

However, there can be cases where the error log itself goes missing or show up some problems.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to to enable the MySQL error log cPanel.

In this context, we shall look into steps to enable the MySQL error log and fix its related errors.


How to enable MySQL Error Log cPanel?

Log files play a vital role during troubleshooting any error.  

We can investigate the root causes for MySQL errors and any unexpected trouble related to it through MySQL error log cPanel.  

So, it is necessary to enable the MySQL Error log cPanel.

The default path of MySQL error log is /var/lib/mysql/{SERVER_NAME}.err.

Generally, the MySQL logs automatically save in the location /var/lib/mysql. Also, all the error log contents store in the file /var/lib/mysql/hostname.err

The hostname is the name of the account. We can change this filename if necessary and also provide a different location as well.

Below is the code that we add to the configuration file:

[mysqld]
log_error = /var/log/mysql/error.log


Here, a different name can be set for the file instead of error.log. 

We create that file with the right permissions and ownership using the below commands:

cd /var/lib/mysql
touch error.log
chmod 660 error.log
chown mysql:mysql error.log

Finally,  we can restart the MySQL service using the command:

systemctl start mysqld


Common errors related to MySQL error log cPanel and its fixes ?

Now, let's see some errors related to MySQL error logs and how our Support Experts fix them.


Error log file unavailable

One of our customers approached us telling us that he was not able to find the MySQL error log file.

Also, he mentioned about the error log file generation in my.cnf file.

So, our Support Experts started troubleshooting the issue by checking the code which was set in my.cnf file. 

The code was as below:

[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

The error logs of MySQL actually logs in the path /var/lib/mysql/{SERVER_NAME}.err

If a different name or location needs to be set then the error log must be mentioned under [mysqld] section and not under the [mysqld_safe] section. 

And the below code can be put within it:

log-error=/var/lib/mysql/error.log

Or instead of error.log, a different name can be set. 

Our Support Experts created that file with the right permissions and ownership:

cd /var/lib/mysql
touch error.log
chmod 660 error.log
chown mysql:mysql error.log

However, the default MySQL errors stores in /var/lib/mysql/{SERVER_NAME}.err itself.

Then, we restarted the MySQL service using the below command:

systemctl start mysqld

Finally, the customer was able to find the desired error log file in the desired location.


[Need urgent assistance with MySQL error logs? – We'll help you. ]


Conclusion

This article will guide you on more information about MySQL error logs and methods to resolve its errors. 

You will learn how to fix MySQL errors, crashes and other unexpected behavior from #MySQL. 

To view mysql error logs:

1. edit /etc/my.cnf [mysqld] log=/tmp/mysql.log.

2. restart the computer or the mysqld service service mysqld restart.

3. open phpmyadmin/any application that uses mysql/mysql console and run a query.

4. cat /tmp/mysql.log ( you should see the query ).

To Clear cPanel Error Log:

1. Login to your server using an #SSH client.

2. To clear the #Apache #errors, type the following and press Enter. cat /dev/null> /usr/local/apache/logs/error_log.

3. To delete PHP error_log files, type the following and press Enter. find /home -type f -name error_log -delete.