2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AIで競輪予想 その4

Posted at

#MySQLクライアントのインストール

mysqlclient
#apt-get install -y libmysqlclient-dev
#pip3 install mysqlclient

下記、ソースで、import MySQLdb の部分でエラーが発生して少しはまった。

mysql-conn-test.py
import MySQLdb

conn = MySQLdb.connect(
    user='root',
    passwd='your-password',
    host='localhost',
    db='your-dbname')

cur = conn.cursor()

cur.execute('DROP TABLE items')
cur.execute('''
    CREATE TABLE items (
        item_id INTEGER PRIMARY KEY AUTO_INCREMENT,
        name TEXT,
        price INTEGER
    )
    ''')

data = [('test1', 100),('test2', 200), ('test3', 300)]
for i in data:
    cur.execute("INSERT INTO items(name,price) VALUES(%s,%s)", i)

conn.commit()

cur.execute("SELECT * FROM items")
for row in cur.fetchall():
    print(row)

これでやっと、python3 + MySQLでの開発環境が整った。

以下の本を参考にした。


Pythonによるスクレイピング&機械学習 開発テクニック BeautifulSoup,scikit-learn,TensorFlowを使ってみよう

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?