Skip to content

Instantly share code, notes, and snippets.

@Kidinnu
Last active April 1, 2020 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kidinnu/52c6f6f52756ca3a586fbe797b2d6443 to your computer and use it in GitHub Desktop.
Save Kidinnu/52c6f6f52756ca3a586fbe797b2d6443 to your computer and use it in GitHub Desktop.
Подключение к mySQL из питона
import pymysql
mydb = pymysql.connect(
host="192.168.0.1", # Адрес сервера
user="user123", # Имя пользователя
passwd="*******", # Пароль
database="mydatabase" # Имя базы данных
)
mycursor = mydb.cursor()
mycursor.execute("DROP TABLE IF EXISTS customers ")
mycursor.execute("CREATE TABLE customers (id SERIAL, name VARCHAR(255), address VARCHAR(255))")
mycursor.execute("INSERT INTO customers (name, address) VALUES('John','14 Street')")
connection.commit()
mycursor.close()
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment