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 3 years have passed since last update.

pythonからsql

Posted at

w3schoolsのチュートリアルを最初からやったほうがいいかもしれない。
https://www.w3schools.com/python/python_mysql_getstarted.asp

ループで変数をinsertするときに%sするのを忘れていた
https://www.w3schools.com/python/python_mysql_insert.asp
'''
import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
passwd="yourpassword",
database="mydatabase"
)

mycursor = mydb.cursor()

sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
val = ("John", "Highway 21")
mycursor.execute(sql, val)

mydb.commit()

print(mycursor.rowcount, "record inserted.")
'''

UNIQUE Constraintについて
https://www.w3schools.com/sqL/sql_unique.asp

pandasでto_sql
https://www.haya-programming.com/entry/2019/05/03/043334

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?