LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-04-2014, 01:30 AM   #1
Glenn D.
Member
 
Registered: May 2009
Location: ACT - Australia
Distribution: Opensuse x86_64 (Latest)
Posts: 132

Rep: Reputation: 26
How can I call-run mysql commands from apache and show the result in apache


Hello,
How can I call-run mysql commands from apache and show the result in apache [1][3]
The output would be similar as shown in [3]
I use opensuse 13.1x
Thanks Glenn

[1]
# cat show-tables.sql
use mysql;
show tables;
exit

[2]
mysql < show-tables.sql

[3]
# mysql -u root < show-tables.sql
Tables_in_mysql
columns_priv
db
event
func
general_log
help_category
help_keyword
help_relation
help_topic
host
ndb_binlog_index
plugin
proc
procs_priv
proxies_priv
servers
slow_log
tables_priv
time_zone
time_zone_leap_second
time_zone_name
time_zone_transition
time_zone_transition_type
user
 
Old 04-04-2014, 01:56 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
hi,

The easiest way is probably with a CGI script (placed in /srv/www/cgi-bin/ on most Linux systems).

Here's some sample code:

Code:
#!/bin/bash
echo -e "Content-Type: text/plain\n"
echo "show tables;" | /usr/bin/mysql -u root mysql
The "use mysql" is replaced by the database name on the command line, and the "exit" is implied by the end of input file, leaving only the "show tables". If you prefer the long syntax, or want to add more SQL commands, this format should work:

Code:
#!/bin/bash
echo -e "Content-Type: text/plain\n"
/usr/bin/mysql -u root <<!SQL
use mysql;
show tables;
exit;
!SQL
In both cases, you might need to change path names & user names (root in my example). You might also have to specify a password.

This (list of tables) is potentially sensitive information, which could help a hacker craft an attack against your DB, so don't expose it to too many people unnecessarily :-)

I hope this helps.

Regards,

Clifford
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Connection issue involving mysql when run through apache php but not through cli php. sasheto86 Linux - Server 2 01-24-2013 09:43 AM
How-To run Apache, php, MySQL on startup and install phpMyAdmin - Slackware 12.2 Penthux Slackware 22 10-07-2012 10:44 PM
[SOLVED] How to run two commands from a exec call in a c program suryashikha Programming 9 11-04-2009 04:14 AM
hostname, modprobe, run apache + mysql on startup intense Slackware 7 03-19-2004 09:09 AM
Apache and MySQL servers won't run at startup! dday007 Linux - Newbie 2 02-07-2003 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:59 PM.

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