mysql init-file config option giving file not found error

Solution 1:

Thanks @quanta, the problem was indeed apparmor.

To fix the issue:

Edit the mysql apparmor file:

sudo emacs -nw /etc/apparmor.d/usr.sbin.mysqld

Include the folder where your init-file lives with the *.sql extension:

...
/usr/sbin/mysqld {
    /var/log/mysql.log rw,
    /var/log/mysql.err rw,
    ;/var/lib/mysql/ r,
    /var/lib/mysql/** rwk,
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    /{,var/}run/mysqld/mysqld.pid w,
    /{,var/}run/mysqld/mysqld.sock w,

    /sys/devices/system/cpu/ r,

    # I added to allow my init-file script to run
    /etc/mysql/*.sql r,
}

And then make AppArmor reload the profiles.

# sudo /etc/init.d/apparmor reload

Then reload mysql:

sudo /etc/init.d/mysql restart

Now the init-file gets executed. Yay!