Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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))
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
1  
If so, try to stop AppArmor and see if the error go away. –  quanta Nov 12 '11 at 1:47
add comment

1 Answer

up vote 3 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/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!

share|improve this answer
    
Feel free to accept it as an answer. –  quanta Nov 12 '11 at 12:47
add comment

Your Answer

 
discard

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.