On the Linux server, MySQL runs slowly and the CPU usage sometimes exceeds 80%. Therefore, find my. cnf, modify related configurations, and add logs to check which SQL statements affect performance:
On the Linux server, MySQL runs slowly and the CPU usage sometimes exceeds 80%. Therefore, find my. cnf, modify related configurations, and add logs to check which SQL statements affect performance:
A few days ago, MySQL running on the Linux server was slow and the CPU usage sometimes exceeded 80%. So I found my. cnf, modified the related configuration, and added the log to see which SQL statements affect performance:
Result After the mysql service is restarted, no logs are generated. Check the mysql error log.
/Usr/sbin/mysqld: File '/home/mysql/log/mysql-slow.log' not found (Errcode: 13)
120224 14:00:17 [ERROR] cocould not use/home/mysql/log/mysql-slow.log for logging (error 13 ). turning logging off for the whole duration of the MySQL server process. to turn it on again: fix the cause, shutdown the MySQL server and restart it.
Searching on the internet indicates that mysql has a permission to read and write files. Therefore, use chmod and chown to change/home and Its subfolders and files to mysql users.
# Touch/var/log/mysql/mysql-slow.log
# Chmod 777/var/log/mysql/mysql-slow.log# chown mysql:mysql /var/log/mysql/mysql-slow.log
Then restart the service, the error persists, the mysql-slow.log file is still empty.
Go to Google to search for the main directory of the mysql account in the/etc/passwd file, but find that the main directory of the mysql account is "/home/mysql ", is mysql not authorized to operate sub-directories in the main directory?
So change the location in the log to "/home/mysql/mysql-slow.log", restart the mysql service, the error is still!
It's a little broken ...... After two days of hard work, I had no results. I had to pause it first, but there was no log. mysql could work, and the CPU usage had already been reduced to less than 10%.
To export the data of a table just the day before, select * into outfile '/home/mysql/data. SQL' and mysql prompts an error:
ERROR 1 (HY000): Can't create/write to file '/home/mysql/data. SQL' (Errcode: 13)
Check whether the error code is correct. Similar errors have also been encountered before. If exported to the/tmp directory, there is no problem. However, through the "ls-l" command, it is confirmed that/home/mysql has all been changed to mysql users, and it also has read and write permissions. Why can't it still be operated?
In addition to despair, I finally found the final solution on the Internet:
# Setsebool-P mysqld_disable_trans = 1
After executing the preceding command, restart the mysql service and the log is generated. Select * into outfile is also executed normally !!!
The following is an excerpt from the detailed introduction on the web page.