Use unix socket authentication without defaults file
I ran into an issue when running mysql-backup.cron with MySQL 8.0 on Debian 12. It triggered the fatal Need MYSQLPASS and MYSQLUSER, or a readable $DEFAULTSFILE
error. This is because the MySQL package does not come with the defaults file: /etc/mysql/debian.cnf
.
MariaDB does come with this file, where it contains a warning:
# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE.
# This file exists only for backwards compatibility for
# tools that run '--defaults-file=/etc/mysql/debian.cnf'
# and have root level access to the local filesystem.
# With those permissions one can run 'mariadb' directly
# anyway thanks to unix socket authentication and hence
# this file is useless. See package README for more info.
The rest of the contents triggers the use of unix socket authentication.
With all that, I believe mysql-backup.cron should support using unix socket authentication even if this defaults file does not exist.
In this PR, I changed the authentication check to primarily use username and password if they are set, then the defaults file if it exists, and finally resort to unix socket authentication (empty $AUTHSTRING
).