I have a script that do some controls and update a mysql entry given the result. In detail, the script calls this command
mysql --database="mydatabase" --execute="UPDATE mytable SET current_value=\"$CONTROL_RESULT\" WHERE name=\"register_name\";"
The script works correctly when run manually from terminal.
I've added a line in /etc/rc.local to run it on startup, and in this case the script returns the error
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
More precisely, if I run /etc/rc.local manually it works (as expected; it's the same as running the script manually); when /etc/rc.local runs on system startup I get this error.
What I've done so far is granting all privileges to root user and adding root password in /root/.my.cnf (if I access mysql with mysql -u root
it doesn't ask me any password). These are the main suggestion I found in other discussions, that awfully are always related to an error when accessing mysql -u username
, that works like a charm in my case.
Any idea about what can be the problem? And hopefully how to get rid of the error?
I'm working on Linux (as you've already guessed...). Here are the mysql version info
mysql> SHOW VARIABLES LIKE "%version%"; +-------------------------+-------------------------+ | Variable_name | Value | +-------------------------+-------------------------+ | innodb_version | 5.5.50 | | protocol_version | 10 | | slave_type_conversions | | | version | 5.5.50-0ubuntu0.14.04.1 | | version_comment | (Ubuntu) | | version_compile_machine | armv7l | | version_compile_os | debian-linux-gnu | +-------------------------+-------------------------+