<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HOWTO: query MySQL from Splunk on Linux 64bit in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/HOWTO-query-MySQL-from-Splunk-on-Linux-64bit/m-p/71241#M995</link>
    <description>&lt;P&gt;This has been tested on Red Hat Enterprise Linux 5.5, 64 bit. It would probably work even easier on Ubuntu Lucid, for obvious reasons. If anyone has any suggestions for changes (especially if you know where to get the files below without stripping things out of DEBs) please comment!
&lt;BR /&gt;&lt;BR /&gt;
&lt;SUB&gt;(If you know where to get the proper files for your distro, feel free to use that if you can find the exact packages - MySQLdb requires libmysqlclient version 16, not 15 which comes with many distros. RPMs may be able to be found online; it looks like  &lt;A href="http://rpmfind.net/linux/RPM/" rel="nofollow"&gt;http://rpmfind.net/linux/RPM/&lt;/A&gt; may have a version 16 from OpenSUSE. I did not test the file from the package listed there.)&lt;/SUB&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;B&gt;Installing MySQLdb 1.2.2 python library on RHEL 64bit server, using Ubuntu parts&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;
1. Download &lt;CODE&gt;libmysqlclient16&lt;/CODE&gt; DEB package from &lt;A href="http://packages.ubuntu.com/lucid/amd64/libmysqlclient16/download" rel="nofollow"&gt;http://packages.ubuntu.com/lucid/amd64/libmysqlclient16/download&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
2. Use Windows &lt;A href="http://www.7-zip.org/" rel="nofollow"&gt;7-Zip&lt;/A&gt; (or any other method you can) to pull &lt;CODE&gt;data.tar.gz/usr/lib/libmysqlclient_r.so.16.0.0&lt;/CODE&gt; from the DEB file&lt;BR /&gt;&lt;BR /&gt;
3. Rename &lt;CODE&gt;libmysqlclient_r.so.16.0.0&lt;/CODE&gt; to &lt;CODE&gt;libmysqlclient_r.so.16&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
4. Put the &lt;CODE&gt;libmysqlclient_r.so.16&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
5. Download &lt;CODE&gt;python-mysqldb&lt;/CODE&gt; DEB from &lt;A href="http://packages.ubuntu.com/lucid/amd64/python-mysqldb/download" rel="nofollow"&gt;http://packages.ubuntu.com/lucid/amd64/python-mysqldb/download&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
6. Use Windows 7-Zip (or any other method you can) to pull &lt;CODE&gt;data.tar.gz&lt;/CODE&gt; from the DEB&lt;BR /&gt;&lt;BR /&gt;
7. Put the &lt;CODE&gt;data.tar.gz/usr/lib/pyshared/python2.6/_mysql.so&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
8. Put the &lt;CODE&gt;data.tar.gz/usr/share/pyshared/_mysql_exceptions.py&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
9. Put the &lt;CODE&gt;data.tar.gz/usr/share/pyshared/MySQLdb/&lt;/CODE&gt; folder in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/site-packages/&lt;/CODE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
The python MySQLdb module is now installed in Splunk's python. Now you can write scripts like the following MySQLdb-based search script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import csv,sys
import MySQLdb

#Define database connection, get cursor
db = MySQLdb.connect(host='ho.st.name',user='username',passwd='password',db='database')
cu = db.cursor(MySQLdb.cursors.DictCursor)

#Define output objects
header = ['input','output']
csv.writer(sys.stdout).writerow(header)
w = csv.DictWriter(sys.stdout, header)

#Query database for results
result = {}
result['input'] = sys.argv[1]
cu.execute("SELECT output FROM table WHERE id='%s'" % db.escape_string(result['input']))
qr = cu.fetchall()

#Output results
if qr == None:
        result['output'] = "None"
        w.writerow(result)
else:
        for row in qr:
                result['output'] = row['output']
                w.writerow(result)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 15 Oct 2010 21:40:49 GMT</pubDate>
    <dc:creator>Jason</dc:creator>
    <dc:date>2010-10-15T21:40:49Z</dc:date>
    <item>
      <title>HOWTO: query MySQL from Splunk on Linux 64bit</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/HOWTO-query-MySQL-from-Splunk-on-Linux-64bit/m-p/71240#M994</link>
      <description>&lt;P&gt;I need to get data from a MySQL server with Splunk, either for a scripted lookup or a scripted input. I have seen a few posts mentioning getting MySQL connectivity set up in Splunk, but I am on a restricted user that can not install any server-wide packages.&lt;/P&gt;

&lt;P&gt;What is a simple way that I can get it working by copying files into Splunk folders only?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Oct 2010 21:20:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/HOWTO-query-MySQL-from-Splunk-on-Linux-64bit/m-p/71240#M994</guid>
      <dc:creator>Jason</dc:creator>
      <dc:date>2010-10-15T21:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: HOWTO: query MySQL from Splunk on Linux 64bit</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/HOWTO-query-MySQL-from-Splunk-on-Linux-64bit/m-p/71241#M995</link>
      <description>&lt;P&gt;This has been tested on Red Hat Enterprise Linux 5.5, 64 bit. It would probably work even easier on Ubuntu Lucid, for obvious reasons. If anyone has any suggestions for changes (especially if you know where to get the files below without stripping things out of DEBs) please comment!
&lt;BR /&gt;&lt;BR /&gt;
&lt;SUB&gt;(If you know where to get the proper files for your distro, feel free to use that if you can find the exact packages - MySQLdb requires libmysqlclient version 16, not 15 which comes with many distros. RPMs may be able to be found online; it looks like  &lt;A href="http://rpmfind.net/linux/RPM/" rel="nofollow"&gt;http://rpmfind.net/linux/RPM/&lt;/A&gt; may have a version 16 from OpenSUSE. I did not test the file from the package listed there.)&lt;/SUB&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;B&gt;Installing MySQLdb 1.2.2 python library on RHEL 64bit server, using Ubuntu parts&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;
1. Download &lt;CODE&gt;libmysqlclient16&lt;/CODE&gt; DEB package from &lt;A href="http://packages.ubuntu.com/lucid/amd64/libmysqlclient16/download" rel="nofollow"&gt;http://packages.ubuntu.com/lucid/amd64/libmysqlclient16/download&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
2. Use Windows &lt;A href="http://www.7-zip.org/" rel="nofollow"&gt;7-Zip&lt;/A&gt; (or any other method you can) to pull &lt;CODE&gt;data.tar.gz/usr/lib/libmysqlclient_r.so.16.0.0&lt;/CODE&gt; from the DEB file&lt;BR /&gt;&lt;BR /&gt;
3. Rename &lt;CODE&gt;libmysqlclient_r.so.16.0.0&lt;/CODE&gt; to &lt;CODE&gt;libmysqlclient_r.so.16&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
4. Put the &lt;CODE&gt;libmysqlclient_r.so.16&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
5. Download &lt;CODE&gt;python-mysqldb&lt;/CODE&gt; DEB from &lt;A href="http://packages.ubuntu.com/lucid/amd64/python-mysqldb/download" rel="nofollow"&gt;http://packages.ubuntu.com/lucid/amd64/python-mysqldb/download&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;
6. Use Windows 7-Zip (or any other method you can) to pull &lt;CODE&gt;data.tar.gz&lt;/CODE&gt; from the DEB&lt;BR /&gt;&lt;BR /&gt;
7. Put the &lt;CODE&gt;data.tar.gz/usr/lib/pyshared/python2.6/_mysql.so&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
8. Put the &lt;CODE&gt;data.tar.gz/usr/share/pyshared/_mysql_exceptions.py&lt;/CODE&gt; file in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/&lt;/CODE&gt;&lt;BR /&gt;&lt;BR /&gt;
9. Put the &lt;CODE&gt;data.tar.gz/usr/share/pyshared/MySQLdb/&lt;/CODE&gt; folder in &lt;CODE&gt;$SPLUNK_HOME/lib/python2.6/site-packages/&lt;/CODE&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
The python MySQLdb module is now installed in Splunk's python. Now you can write scripts like the following MySQLdb-based search script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import csv,sys
import MySQLdb

#Define database connection, get cursor
db = MySQLdb.connect(host='ho.st.name',user='username',passwd='password',db='database')
cu = db.cursor(MySQLdb.cursors.DictCursor)

#Define output objects
header = ['input','output']
csv.writer(sys.stdout).writerow(header)
w = csv.DictWriter(sys.stdout, header)

#Query database for results
result = {}
result['input'] = sys.argv[1]
cu.execute("SELECT output FROM table WHERE id='%s'" % db.escape_string(result['input']))
qr = cu.fetchall()

#Output results
if qr == None:
        result['output'] = "None"
        w.writerow(result)
else:
        for row in qr:
                result['output'] = row['output']
                w.writerow(result)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Oct 2010 21:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/HOWTO-query-MySQL-from-Splunk-on-Linux-64bit/m-p/71241#M995</guid>
      <dc:creator>Jason</dc:creator>
      <dc:date>2010-10-15T21:40:49Z</dc:date>
    </item>
  </channel>
</rss>

