mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Could not open file '/var/log/mysql/error.log' for error logging: Permission denied

Open joylili opened this issue 6 years ago • 3 comments

version:mysql8.0.20 I want to record the log file to the directory /var/log/mysql,error "Could not open file '/var/log/mysql/error.log' for error logging: Permission denied".Now II can only record in /var/lib/mysql。So,mysql data and logs are in one director.Can log directories be used as parameters to support other locations, for example /var/log/mysql.

joylili avatar Jun 24 '20 09:06 joylili

mysql runs as the user mysql so you'll want to adjust permissions on /var/log/

$ docker build -t mysql:test - << EOF
> FROM mysql
> RUN mkdir /var/log/mysql && chmod 777 /var/log/mysql
> EOF
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM mysql
 ---> be0dbf01a0f3
Step 2/2 : RUN mkdir /var/log/mysql && chmod 777 /var/log/mysql
 ---> Running in 902f39ea4f86
Removing intermediate container 902f39ea4f86
 ---> f0be091b31a1
Successfully built f0be091b31a1
Successfully tagged mysql:test

$ docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=root mysql:test --log-error=/var/log/mysql/error
950774855eb2a6dae69db08f0c36c874585ed45533ac3ae28a48c9cc5004c165

Also note that this will affect docker logs output as it's not being directed to stderr anymore

$ docker logs -f mysql
2020-06-24 15:51:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-06-24 15:51:42+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-06-24 15:51:42+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-06-24 15:51:42+00:00 [Note] [Entrypoint]: Initializing database files
2020-06-24 15:51:46+00:00 [Note] [Entrypoint]: Database files initialized
2020-06-24 15:51:46+00:00 [Note] [Entrypoint]: Starting temporary server
2020-06-24 15:51:47+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.

2020-06-24 15:51:51+00:00 [Note] [Entrypoint]: Stopping temporary server
2020-06-24 15:51:54+00:00 [Note] [Entrypoint]: Temporary server stopped

2020-06-24 15:51:54+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

$ docker exec -it mysql bash

root@950774855eb2:/# cd /var/log/mysql/

root@950774855eb2:/var/log/mysql# ls -al
total 4
drwxrwxrwx 1 root  root    23 Jun 24 15:51 .
drwxr-xr-x 1 root  root    19 Jun 24 15:51 ..
-rw-r----- 1 mysql mysql 3421 Jun 24 15:51 error.err

You could also try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow. Since these repos aren't really a user-help forum

wglambert avatar Jun 24 '20 16:06 wglambert

Thank you for the post. Before that i did not get any meaningful error messages. After deleting and recreating those folders, i saw [ERROR] Could not open file '/var/log/mysqld.log' for error logging. Tried moving the log file, that did not help. Compared the permissions to the working environment, they were identical. I was able to fix it by changing the log-error statement in /etc/my.cnf to a different folder (e.g. /home/mysql_logs/mysqld.log). I am still not sure why did it happen. I had this happened on the master mysql. Then after i switched to the replica, it happened to the replica db few days later... Hope that helps someone else.

pioneer903 avatar Oct 06 '22 18:10 pioneer903

$ docker build -t mysql:test - << EOF
> FROM mysql
> RUN mkdir /var/log/mysql && chmod 777 /var/log/mysql
> EOF

$ docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=root mysql:test --log-error=/var/log/mysql/error

After running this, my aws ec2 instance became quite slow, and after several minutes, CPU goes to 100%

domeniczz avatar Apr 22 '23 13:04 domeniczz