11

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
...
[mysqld]
init-file=/etc/mysql/mysqlinit.sql
...

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?


Info:

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))
Tom
  • 4,157
  • 11
  • 41
  • 52

1 Answers1

15

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!

Tom
  • 4,157
  • 11
  • 41
  • 52