MySQLdb is a Python wrapper around _mysql written by Andy
Dustman. This wrapper makes it possible to interact with a MySQL
Server performing all sorts of DDL and DML statements. I began my
Python journey recently and stumbled at the installation of the
MySQLdb module install. I was keen not to jump at an apt/yum
installation as we have servers that have no outbound connections
I decided I wanted to build the module from source.
You can download the MySQLdb files from SourceForge (70kb)
When downloaded you need to prep before your system is ready to
build the file. Here are some prerequisites that will
make life easier for you. I performed this particular install
using an Ubuntu 10.04 64bit OS.
Before you start ensure you have the following installed (MySQL
isn't actually required but for local Python development …
If you need to work with LVM in your scripts but haven’t found a good method to access details about Logical Volume Groups, here’s a simple Python script that will print the details about any volumes on your system. This could be useful for writing a partition check script for your MySQL data directory (if you’re not using a standard monitoring system like Nagios).
import sys
import os
import commands
import subprocess
import select
def lvm():
print ""
LVM_PATH = "/sbin"
LVM_BIN = os.path.join(LVM_PATH, 'lvm')
argv = list()
argv.append(LVM_BIN)
argv.append("lvs")
argv.append("--nosuffix")
argv.append("--noheadings")
argv.append("--units")
argv.append("b")
argv.append("--separator")
argv.append(";")
argv.append("-o")
argv.append("lv_name,vg_name,lv_size")
process = subprocess.Popen(argv, stdout=subprocess.PIPE)
output = ""
out = process.stdout.readline()
output += out
lines = …[Read more]
If you’ve been looking for a simple python script to use with MySQL that you can use to expand upon for your next project, check this one out. It has error handling for the connection, error handling for the sql call, and loop iteration for the rows returned.
#!/usr/bin/python
import sys
import MySQLdb
my_host = "localhost"
my_user = "user"
my_pass = "password"
my_db = "test"
try:
db = MySQLdb.connect(host=my_host, user=my_user, passwd=my_pass, db=my_db)
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor = db.cursor()
sql = "select column1, column2 from table";
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
column1 = row[0]
column2 = row[1]
print "column1: %s, column2: %s"%(column1,column2)
db.close()
|
If you have tried Quick start guides: MySQL cluster in 10
minutes, you may have realized that it is really quick
and easy. However, it leaves some typing to be done. Users of MySQL Sandbox have a horror of repetitive typing, and this got me thinking. "Could I integrate MySQL Sandbox and Cluster?" The answer was: "Sure." But then I started thinking of all the minor and major changes that I wanted to do to the Sandbox and have delayed for too long. What I need, is a radical refactoring. And then I remembered that it has been almost two years since I learned a new programming language and that perhaps I could expand my horizons … |
We just released MySQL Connector/Python 0.1.5 which includes a critical bug fix. It was impossible to read big result sets. The files for 0.1.4-release have been removed.
You can download MySQL Connector/Python from Launchpad.
Highlights:
- It was impossible to retrieve big result sets. (bug lp:551533 and lp:586003)
- Changing copyright from Sun to Oracle (also fixing silly typo)
A very Big Thanks goes to the reporters of bug lp:551533 and lp:586003. Apologies for not being able to reproduce the bug earlier, before releasing 0.1.4.
About MySQL Connector/Python: MySQL …
[Read more]Next development release 0.1.4 of MySQL Connector/Python is now available for download. This will be the last in the 0.1-series as we move on to 0.2. The aim is to release more often to get to v1.0. Hurray!
Highlights:
- Reading from network was broken for bigger packages.
- Reimplementing protocol.MySQLProtocol marking simpler and easier to maintain.
- It is now possible to send multiple statements to MySQL using MySQLCursor.execute(). The results are accessible by calling the method next_resultset().
- MySQLCursor.callproc() will now store all result sets as a MySQLCursorBuffered. They are accessible using the next_proc_resultset() method. The result of the stored procedure is returned by callproc() itself as defined by PEP249.
- MySQL …
Just a quick notice to let everyone know that there is a new version of Kontrollkit available. There are some required bug fixes to the formerly new python backup script and some Solaris compatible changes to the various my.cnf files. You can download the new version here: http://kontrollsoft.com/software-downloads, or here: http://code.google.com/p/kontrollkit/
A special extended edition of Tech Messages for 2010-04-15 through 2010-04-24:
-
The Onion Uses Django, And Why It Matters To
Us
I love Django too. - Open Source Network Monitoring and Systems Management - Zenoss Blog: No Node Left Behind: Datacenter Barometer: BitNami Simplifies Stacks
-
mysql-cacti-templates
Offers complete templates and a method for adding your own. Highly recommended. -
Increase maximum size of PST files
Microsoft Outlook …
I’ve recently had the pleasure of reading “Python Testing: An easy and convenient approach to testing your python projects” from Packt Publishing. It’s been a quick read but a solid set of instructions on the different methods for the subject.
The book starts out very quickly with details about the various methods that are available, the means of automation for testing, and of course the environment you’d want to be in for working on the subjects that the book covers. It then, in the second chapter, moves into the guts of testing by describing the basics of doctest via syntax and some simple examples, and then moves on to a real world example via the AVL tree. It’s all very basic testing until chapter three where the author gets into unit testing, …
[Read more]I’ve been wanting to write a backup script for a while now that does the following: reads the partition information for the directory that you are backing up into and computes the used/available/percentage-available space. Then it reads the total data size from the MySQL tables and ensures that you have enough space on disk (for [...]