Good! I worked effectively a whole day with new version of Ubuntu, PHP 7.0 and MySQL 5.7.
What large surprize it was for me when I discovered next morning that MySQL service can not be started. Moreover it said nothing about the reason except:
Job for mysql.service failed because the control process exited with error code.
See “systemctl status mysql.service” and “journalctl -xe” for details.
and with more details but still useless:
— Unit mysql.service has begun starting up.
May 03 14:59:18 eagle systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
I spent a lot of time trying to find and isolate a reason of such MySql failure. I fully reinstalled MySQL few times. I even tried a MariaDB fork. But every time I finished with the same result. Database server worked fine after its installation, but failed to start at once after the 1st reboot.
What’s the difference? I found myself at the state near to a dead lock. Dead Lock! 1 hour, 2 hours, 3 hours…
Bingo!
Thanks to SOMEONE who turned that light at my head. I remembered that I use temporary file system mapped to the memory for the system logs and other temporary files.
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 8193016 1428 8191588 1% /var/log
tmpfs 8193016 33952 8159064 1% /tmp
The only difference with tmpfs at RAM is that it’s absolutely clear after system reboot. And this difference may be a reason of MySQL start failure.
I compared tmpfs type folders before and after reboot and discovered that system does not creates /var/log/mysql folder automatically, as other services do, Apache, for example. When I created /var/log/mysql folder manually, MySQL was started from a command line successfully.
The next task I had to resolve how to force my system create /var/log/mysql folder every time after system reboot, but before MySQL server start. So let’s finish with lyrics and return to the subject of this post. I took an idea from this post. Finally a solution is:
1) Create the file /etc/init.d/mysql-logs
with this content
#!/bin/bash # ### BEGIN INIT INFO # Provides: mysql-logs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Required-Start: # Required-Stop: # Short-Description: Create the mysql work environment at startup # Description: Create the /var/log/mysql ### END INIT INFO # # main() # case "${1:-''}" in 'start') #create the /var/log/mysql mkdir -p /var/log/mysql chown mysql:root /var/log/mysql ;; 'stop') ;; 'restart') ;; 'reload'|'force-reload') ;; 'status') ;; *) echo "Usage: $SELF start|stop" exit 1 ;; esac |
2) Declare it for startup (S18) & shutdown (K22)
$ sudo update-rc.d mysql-logs defaults 18 22
You made it. Just reboot and look at working MySQL.