

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Mysql is a fast, open-source relational database widely used for creating dynamic server-side applications, particularly with php scripts. Known for its power, customizability, and compatibility with various operating systems and programming languages, mysql is a cost-effective solution for businesses. Installation, database setup, accessing data using python, and transactions.
What you will learn
Typology: Lecture notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!
MySQL is a fast, easy to use relational database. It is currently the most popular open- source database. It is very commonly used in conjunction with PHP scripts to create powerful and dynamic server-side applications.
MySQL is used for many small and big businesses. It is developed, marketed and supported by MySQL AB, a Swedish company. It is written in C and C++.
MySQL is becoming so popular because of these following reasons:
import mysql.connector db_connection = mysql.connector.connect( host="hostname", user="username", passwd="password" )
Performing Transactions
Data is stored in a collection of tables with each table consisting of a set of
rows and columns. This is similar to how data is stored in SQLite. To interact
with the data stored in tables we use a special-purpose programming
language called SQL.
Step 1: Install MySQL
First you must install a MySQL driver, use the specific installation method
below.
On Windows:
Install MySQLdb using the installer.
On Linux:
Install MySQLdb using:
sudo apt-get install python-mysqldb yum install mysql-python
depending on your version.
On Mac:
Follow the installation instructions from stackoverflow
MySQL server has to be running before going to the next step.
Step 2: Setup the database
Make sure you have database access, from the command line type:
mysql -u USERNAME -p
MySQL will then ask your password. Type these commands:
mysql> CREATE DATABASE pythonspot; mysql> USE pythonspot;
We go on the create the table:
CREATE TABLE IF NOT EXISTS examples ( id int(11) NOT NULL AUTO_INCREMENT, description varchar(45), PRIMARY KEY (id) );
Then we can insert data into the table (these are SQL queries):
1
2
3
INSERT INTO examples(description) VALUES ("Hello World"); INSERT INTO examples(description) VALUES ("MySQL Example"); INSERT INTO examples(description) VALUES ("Flask Example");
You can now grab all records from the table using a SQL query:
mysql> SELECT * FROM examples; +----+---------------+ | id | description | +----+---------------+ | 1 | Hello World | | 2 | MySQL Example | | 3 | Flask Example | +----+---------------+