1

I have an SQL query that must be run on every startup after a software update (updates come with new installations of mysql and thus change the debian-sys-maint user's password, which my script updates in the database). I have a script that is in /etc/init.d that does this exact thing when I run it as root user: ./update. But when I boot it does not run correctly. I run the service command to get it to run through the init.d process, but it says:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO

I put a plaintext password in /root/.my.cnf to avoid having to use it in various other scripts and to improve security. It can make my mysql call (without -p) perfectly when I call the script manually, but not when I use the service process and not on boot. There was a mention on another question that the environment might not be set up correctly for the script, but I have no idea what environment variables I'd have to set up to call mysql in a script so that it will read /root/.my.cnf.

I have already checked to make sure that the script is owned by root and has 755 permissions. What do I have to do to get this to work?

2 Answers 2

0

When running a init.d, script unless you are explicitly sourcing in that .my.cnf in your init.d script, it will not be used. Kinda like crontab. So try sourcing it in and see if that works.

On a different note, does this script have to log into the DB as root user? I understand why the OS level user needs to be root, but why such a privileged user in the DB itself?

1
  • I have to edit the password for the system user debian-sys-maint, so unless there's a way to do that without using root user I have to; yes.
    – LavaHot
    Commented Nov 4, 2014 at 22:57
0

Turns out that placing sudo in front of the mysql call fixed it and now the call runs correctly. I have no idea:

  1. Why the script is not run as root user.
  2. What user it is running as.
  3. Why that user has sudoer abilities.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .