5: 2016-12-25 (日) 09:53:59 njf[4] [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] |
(This host) = https://njf.jp