I want to have a SQL script run whenever mysql starts but I can't get it working in Ubuntu 11.10.

I added a "init-file" option to the mysql config file:

> sudo emacs -nw /etc/mysql/my.cnf

But when I restart mysql, it fails with a "File not found" error:

> tail /var/log/mysql/error.log
111111  7:41:06 [ERROR] /usr/sbin/mysqld: File '/etc/mysql/mysqlinit.sql' not found (Errcode: 13)
111111  7:41:06 [ERROR] Aborting

But the file certainly exists and is readable:

> ls -l /etc/mysql/mysqlinit.sql
-rwxr-xr-x 1 mysql mysql 30 2011-11-09 05:06 /etc/mysql/mysqlinit.sql

Any ideas how to solve this? Is this a Ubuntu oddness or did I do something dumb?


I'm running Ubuntu 11.10 and MySQL 5.1.

> mysqld --version
mysqld  Ver 5.1.58-1ubuntu1 for debian-linux-gnu on x86_64 ((Ubuntu))
  • What is the output of file /etc/mysql/mysqlinit.sql?
    – quanta
    Nov 11, 2011 at 8:18
  • file /etc/mysql/mysqlinit.sql gives "/etc/mysql/mysqlinit.sql: ASCII text, with no line terminators"
    – Tom
    Nov 11, 2011 at 11:52
  • To narrow down the problem, just try to move it to /tmp folder to see what happens. Are you running AppArmor?
    – quanta
    Nov 11, 2011 at 15:27
  • I tried using a init-file in /tmp but no luck. Yes, I think Ubuntu uses AppArmor.
    – Tom
    Nov 11, 2011 at 16:51
  • 1
    If so, try to stop AppArmor and see if the error go away.
    – quanta
    Nov 12, 2011 at 1:47

1 Answer 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!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.