'Ubuntu 20.04 - Stopped MySQL. Now it won't start (error 13, permission denied)
Running a DigitalOcean LAMP Stack (1GB VPS) on Ubuntu 20.04, I was getting intermittent "Error establshing a database connection" errors in Wordpress when uploading media files. This was throwing the following Apache error:
WordPress database error MySQL server has gone away for query...
While this issue was occurring, MySQL logs repeatedly printed the following and nothing else since:
2020-12-19T12:14:43.708558Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-12-19T12:14:43.992793Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22-0ubuntu0.20.04.3' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu).
2020-12-19T12:14:59.498001Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22-0ubuntu0.20.04.3) starting as process 190645
2020-12-19T12:14:59.512933Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-12-19T12:15:00.093514Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-12-19T12:15:00.448326Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '127.0.0.1' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2020-12-19T12:15:00.524531Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
2020-12-19T12:15:00.543848Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
2020-12-19T12:15:00.652394Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
I tried this fix: WordPress database error MySQL server has gone away for query
Still the website was displaying the error, so I thought I should restart MySQL, but it won't restart.
With sudo service MySQL start
, I get
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
Running the first command:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-12-19 12:45:50 UTC; 1min 3s ago
Process: 192068 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Process: 192076 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
Main PID: 192076 (code=exited, status=1/FAILURE)
Status: "Server startup in progress"
Error: 13 (Permission denied)
Running the second command
Hint: You are currently not seeing messages from other users and the system.
Users in groups 'adm', 'systemd-journal' can see all messages.
Pass -q to turn off this notice.
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 8.
Dec 19 12:13:48 server systemd[189372]: Listening on REST API socket for snapd user session agent.
-- Subject: A start job for unit UNIT has finished successfully
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 11.
Dec 19 12:13:48 server systemd[189372]: Listening on D-Bus User Message Bus Socket.
-- Subject: A start job for unit UNIT has finished successfully
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 9.
Dec 19 12:13:48 server systemd[189372]: Reached target Sockets.
-- Subject: A start job for unit UNIT has finished successfully
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 5.
Dec 19 12:13:48 server systemd[189372]: Reached target Basic System.
-- Subject: A start job for unit UNIT has finished successfully
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 2.
Dec 19 12:13:48 server systemd[189372]: Reached target Main User Target.
-- Subject: A start job for unit UNIT has finished successfully
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit UNIT has finished successfully.
--
-- The job identifier is 1.
Dec 19 12:13:48 server systemd[189372]: Startup finished in 168ms.
-- Subject: User manager start-up is now complete
-- Defined-By: systems
-- Support: http://www.ubuntu.com/support
--
-- The user manager instance for user 1000 has been started. All services queued
-- for starting have been started. Note that other services might still be starting
-- up or be started at any later time.
--
-- Startup of the manager took 168965 microseconds.
Dec 19 12:15:07 server sudo[190726]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
Dec 19 12:15:09 server sudo[190726]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
Dec 19 12:30:17 server sudo[191518]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
Dec 19 12:30:19 server sudo[191518]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
Dec 19 12:32:25 server sudo[191686]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
Dec 19 12:32:27 server sudo[191686]: pam_unix(sudo:auth): Couldn't open /etc/securetty: No such file or directory
The first error led me to this: https://askubuntu.com/questions/1228827/mysql-error-13-permission-denied
However MySQL already owns /var/lib/mysql. The owner of /usr/sbin/mysqld is root. This is the same as on another server where MySQL works fine. Should I really change this?
Solution 1:[1]
The issue was I had given my user ownership of /var/log/mysql to read the files. sudo chown mysql:mysql -R /var/log/mysql
allowed me to start mysql.
Solution 2:[2]
Simple run update command
apt-get update
apt-get upgrade
It auto update permissions necessary for mysql.
It solves my problem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | user16421 |
Solution 2 | Sidedevelopers |