-
-
Save Kidinnu/52c6f6f52756ca3a586fbe797b2d6443 to your computer and use it in GitHub Desktop.
Подключение к mySQL из питона
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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