I have written a CGI script using bash which executes a MySQL query. For MySQL authentication , automatic login is used by supplying the credentials in .my.cnf file as shown below .
# the following section will be read by *all* client programs
[client]
user=dbuser
password=password
Since the CGI program is executed as apache user , I placed the .my.cnf under apache's home directory.
# grep apache /etc/passwd
apache:x:48:48:Apache:/var/www:/sbin/nologin
# ls -l /var/www/.my.cnf
-rw------- 1 apache apache 97 Apr 23 12:36 /var/www/.my.cnf
But looks like this is not working as mysql query is not getting executed . I am confused actually where to put the .my.cnf so that mysql query in CGI script can read it from that location.
Code snippet for the script is as follows
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<body>"
mysql -h 192.168.2.140 -D mysql -e "select User from mysql;"
echo "</body>"
echo "</html>"