sábado, 20 de enero de 2018

python mysql

You need to use one of the following commands. Which one depends on what OS and software you have and use.
  1. easy_install mysql-python (mix os)
  2. pip install mysql-python (mix os)
  3. apt-get install python-mysqldb (Linux Ubuntu, ...)
  4. cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD)
  5. yum install MySQL-python (Linux Fedora, CentOS ...)
For Windows, see this answer: Install mysql-python (Windows)


#!/usr/bin/python

import MySQLdb

# Open database connection
db = MySQLdb.connect("localhost","root","19821982","asterisk" )

# prepare a cursor object using cursor() method
cursor = db.cursor()

# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")

# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print ("Database version : %s ") % data

# disconnect from server
db.close()

No hay comentarios:

Publicar un comentario