Search code examples
mysqlamazon-web-servicesmysql-workbenchamazon-rds

MySQL Workbench error: Lost connection to MySQL server; Terminal error: Error: 13 (Permission denied)


Connection to the MySQL db was working fine 2 weeks ago, and without any editing or development activity it dropped out. I am using SQL Workbench to access. I can connect to the AWS EC2 instance via the AWS dashboard as well as SSH tunnel, can view/access files from filezilla connection.

The server is running WordPress application for a single website (https://farrahstribute.com/)

By examining past answers I tried:

(1) editing /etc/my.cnf and added this line bind-address=0.0.0.0

after adding I rebooted server, however nothing changed, error with db persisting, so I removed the code I added

(2) editing /etc/hosts.allow and added these lines

mysqld: ALL : ALLOW
mysqld-max: ALL : ALLOW

after editing I rebooted server, however nothing changed, error with db persisting, so I removed the code that I added

From the terminal - this command systemctl status mysqld -l gave this result:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2022-11-29 01:22:25 UTC; 14h ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3152 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 2906 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3152 (code=exited, status=1/FAILURE)
   Status: "Server shutdown complete"
    Error: 13 (Permission denied)

Nov 29 01:22:20 ip-172-31-28-111.ec2.internal systemd[1]: Starting MySQL Server...
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal mysqld[3152]: 2022-11-29T01:22:25.558132Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.31) starting as process 3152
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal mysqld[3152]: 2022-11-29T01:22:25.615516Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysqld.log' for error logging: Permission denied
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal mysqld[3152]: 2022-11-29T01:22:25.615582Z 0 [ERROR] [MY-010119] [Server] Aborting
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal mysqld[3152]: 2022-11-29T01:22:25.640431Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal systemd[1]: Failed to start MySQL Server.
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal systemd[1]: Unit mysqld.service entered failed state.
Nov 29 01:22:25 ip-172-31-28-111.ec2.internal systemd[1]: mysqld.service failed.

Also from the terminal ran: systemctl status mysqld.service with output:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2022-11-29 15:42:23 UTC; 2min 7s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 7247 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 7220 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 7247 (code=exited, status=1/FAILURE)
   Status: "Server shutdown complete"
    Error: 13 (Permission denied)

Nov 29 15:42:22 ip-172-31-28-111.ec2.internal systemd[1]: Starting MySQL Server...
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal mysqld[7247]: 2022-11-29T15:42:23.292440Z 0 [System] [MY-010116] [Server...7247
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal mysqld[7247]: 2022-11-29T15:42:23.296242Z 0 [ERROR] [MY-010187] [Server]...nied
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal mysqld[7247]: 2022-11-29T15:42:23.297482Z 0 [ERROR] [MY-010119] [Server]...ting
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal mysqld[7247]: 2022-11-29T15:42:23.297889Z 0 [System] [MY-010910] [Server...GPL.
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal systemd[1]: Failed to start MySQL Server.
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal systemd[1]: Unit mysqld.service entered failed state.
Nov 29 15:42:23 ip-172-31-28-111.ec2.internal systemd[1]: mysqld.service failed.

I also examined the error log /var/log/nginx/farrahstribute_error.log and found this error:

2022/11/29 00:55:06 [error] 3111#3111: *39 access forbidden by rule, client: 54.152.255.102, server: farrahstribute.com, request: "GET /.env HTTP/1.1", host: "34.199.116.152"

Solution

  • the issue is this line:

     [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysqld.log' for error logging: Permission denied
    

    Which is supported by this error message: Error: 13 (Permission denied)

    So the issue is permissions to the /var/log/mysqld.log file. What is needed is to create permissions for mysql to access this file - running this command with a server reboot solved this issue:

    $ sudo chown mysql:mysql /var/log/mysqld.log