ページへ戻る

− Links

 印刷 

Python​/MySQLから使う基礎 の変更点 :: NJF Wiki

xpwiki:Python/MySQLから使う基礎 の変更点

« Prev[3]  
5: 2016-12-25 (日) 09:53:59 njf[4] ソース[5] バックアップ No.5 を復元して編集[6] 現: 2017-09-17 (日) 13:57:55 njf[4] ソース[7] 編集[8]
Line 2: Line 2:
MySQLのインストールは他にたくさん資料があるのでそちらを参照のこと。 MySQLのインストールは他にたくさん資料があるのでそちらを参照のこと。
-Macならバイナリダウンロードしてインストール、WindowsならWAMPとかVertrigoServが楽かもしれません。+Macならbrewコマンドかバイナリダウンロードしてインストール、WindowsならWAMPとかVertrigoServが楽かもしれません。
Linuxなどはパッケージ管理コマンドで簡単に入るはずです。 Linuxなどはパッケージ管理コマンドで簡単に入るはずです。
Line 19: Line 19:
 import MySQLdb  import MySQLdb
 + 
 connector = MySQLdb.connect(host="localhost",db = "python_test", user="myuser", passwd="mypassword", charset="utf8")  connector = MySQLdb.connect(host="localhost",db = "python_test", user="myuser", passwd="mypassword", charset="utf8")
 cursor = connector.cursor()  cursor = connector.cursor()
 + 
 cursor.execute(u"INSERT INTO test VALUE(1,'This is Test');")  cursor.execute(u"INSERT INTO test VALUE(1,'This is Test');")
 connector.commit()  connector.commit()
Line 60: Line 60:
 import MySQLdb  import MySQLdb
 + 
 connector = MySQLdb.connect(host="localhost",db = "python_test", user="myuser", passwd="mypassword", charset="utf8")  connector = MySQLdb.connect(host="localhost",db = "python_test", user="myuser", passwd="mypassword", charset="utf8")
 cursor = connector.cursor()  cursor = connector.cursor()
 cursor.execute("SELECT * FROM test;")  cursor.execute("SELECT * FROM test;")
 datas = cursor.fetchall()  datas = cursor.fetchall()
 + 
 for row in datas:  for row in datas:
   print row[0],row[1]    print row[0],row[1]
« Prev[3]