LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-23-2014, 05:03 AM   #1
zama
Member
 
Registered: Mar 2012
Posts: 34

Rep: Reputation: Disabled
Automatic login for MySQL through CGI script


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>"

Please suggest how to resolve the issue.

Thanks
Zaman
 
Old 04-24-2014, 08:42 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Quote:
Originally Posted by zama View Post
mysql -h 192.168.2.140 -D mysql -e "select User from mysql;"
I am not sure there should be table name mysql in the database mysql, I think it should be user so try
Code:
mysql -h 192.168.2.140 -D mysql -e "select User from user;"
and it would be good if you use mysql username and mysql password. If you have username root and password blank, do not use it. A fair username and password is more secure than root and blank. Suppose your username is zama and password is zama897456 so it would be
Code:
mysql -h 192.168.2.140 -u zama -p'zama897456' -D mysql -e "select User from user;"

Last edited by eklavya; 04-24-2014 at 08:53 AM.
 
  


Reply

Tags
bash, cgi, mysql



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting mysql using login script zak100 Linux - Newbie 20 10-08-2012 10:22 PM
i want to create a script for automatic login through telent ashu_ky Ubuntu 10 05-05-2012 01:11 PM
Trying to write script that tests mysql login drigby Programming 3 04-09-2012 10:43 AM
Perl quoting issue in CGI script (MySQL program) resetreset Programming 10 01-28-2009 01:25 AM
store list items written in cgi script to mysql database gsr_kashyap Programming 5 01-28-2009 01:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration