Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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))
share|improve this question
What is the output of file /etc/mysql/mysqlinit.sql? – quanta Nov 11 '11 at 8:18
file /etc/mysql/mysqlinit.sql gives "/etc/mysql/mysqlinit.sql: ASCII text, with no line terminators" – Tom Nov 11 '11 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 '11 at 15:27
I tried using a init-file in /tmp but no luck. Yes, I think Ubuntu uses AppArmor. – Tom Nov 11 '11 at 16:51
If so, try to stop AppArmor and see if the error go away. – quanta Nov 12 '11 at 1:47
up vote 8 down vote accepted

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/ 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!

share|improve this answer
Feel free to accept it as an answer. – quanta Nov 12 '11 at 12:47
Awesome. Thanks a lot for the help! – JavaRunner Dec 2 '14 at 20:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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