Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python Backend with MySQL: Setup, Connect, Add, Select, Join, Summaries of Mathematics

Database SystemsDatabase QueryingDatabase DesignDatabase Management Systems

A step-by-step guide on how to set up a Python backend system using the pymysql library, create a MySQL database, connect to it, add and select data, and join tables. The instructions include creating a new database, installing the required library, and writing SQL queries to perform various database operations.

What you will learn

  • How do you join two tables in a MySQL database using Python?
  • What is the syntax for adding a new record to a MySQL database using Python?
  • How do you install the pymysql library in Python?

Typology: Summaries

2019/2020

Uploaded on 11/22/2021

tran-ngoc-truong
tran-ngoc-truong đŸ‡»đŸ‡ł

4

(1)

4 documents

1 / 9

Toggle sidebar

Related documents


Partial preview of the text

Download Python Backend with MySQL: Setup, Connect, Add, Select, Join and more Summaries Mathematics in PDF only on Docsity! Lap trinh hĂ© th6ng backend voi Python Phi Hoang Anh Cai dat thu viĂ©n Cai dat thu viĂ©n: pip install pymysql Tao 1 database: CREATE TABLE user ( id INTEGER NOT NULL, email VARCHAR, password VARCHAR, PRIMARY KEY (id), UNIQUE (email) ) Select / Insert vai nhiĂ©u ban ghi Lay vĂ© tat ca ban ghi: result = cursor.fetchall() # [{'email': 'webmaster@python.org', 'password': 'very-secret'}] Update nhiĂ©u ban ghi: data = [ ('Jane', “Jane ‘s password”) ('Joe', “Joe ‘s password”), ('John', “John ‘s password”) ] stmt = "INSERT INTO users (email, password) VALUES (%s, %S)" cursor.executemany(stmt, data) Insert ignore / On Duplicate key update Insert ignore: cho phĂ©p bo qua cac ban ghi co key da ton tai Sql = "INSERT IGNORE INTO users (email, password) VALUES (‘webmaster@python.org’, ‘very- secret’)" cursor.execute(sql) connection.commit() Insert on duplicate key update: Insert hoac update nĂ©u key bi trung Sql = "INSERT INTO users (email, password) VALUES (‘webmaster@python.org’, ‘very-secret’) ON DUPLICATE KEY UPDATE updated=VALUES(email)" cursor.execute(sql) connection.commit() Join tables Tao thĂ©m 1 bang sau: CREATE TABLE images ( id INTEGER NOT NULL image_path VARCHAR, email VARCHAR, PRIMARY KEY (id) ) sql = “INSERT INTO images (email, image_path) VALUES (‘webmaster@python.org’, ‘my_first_image’ )” cursor.execute(sql) connection.commit() sql = “SELECT users.email, users.password FROM users INNER JOIN images ON users.email=images.email” cursor.execute(sql) # [{'email': 'webmaster@python.org', 'password': 'very-secret'}]
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved