Skip to content

Instantly share code, notes, and snippets.

@hasayvaz
Last active December 14, 2015 09:08
Show Gist options
  • Save hasayvaz/5062414 to your computer and use it in GitHub Desktop.
Save hasayvaz/5062414 to your computer and use it in GitHub Desktop.
connect to remote MySQL database with pyhon
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as may
#veritabanina baglaniyoruz
db = may.connect(host="localhost", user="telrehberi", passwd="123", db="telrehberi")
#cursor() metodunu kullanmak icin bir cursor nesnesi olusturmak
#cursor = db.cursor()
#veritabanındaki rehber tablosunun bilgilerine erismek
#cursor.execute("SELECT * FROM rehber")
#tabloya bilgi eklemek
#cursor.execute("""CREATE TABLE tablo ( ad CHAR(10) NOT NULL, soyad CHAR(20) NOT NULL)""")
#cursor. execute ("""insert into tablo (ad, soyad) values ("5", "hakan")""")
#tablodaki bilgileri cekmek
#result = cursor.fetchall()
#son ekledigimiz satirin idsi
#print cursor.lastrowid
#yeni bir tablo eklemek
#cursor.execute("""CREATE TABLE tablo ( ad CHAR(10) NOT NULL, soyad CHAR(20) NOT NULL)""")
#tablodan bilgi silmek
#cursor.execute("delete from rehber where id > 4")
#veritabani versiyon bilgisi
#cur.execute("SELECT VERSION()")
#data = cur.fetchone()
#baglantilari kapatmak
cursor.close()
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment