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

MySQL: The Popular Open-Source Relational Database, Lecture notes of Database Management Systems (DBMS)

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

  • What is the process of creating and inserting data into a MySQL database using Python?
  • How do you install MySQL on different operating systems?
  • What are the benefits of using MySQL over other databases?

Typology: Lecture notes

2018/2019

Uploaded on 12/02/2019

lalan-rai
lalan-rai 🇮🇳

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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:
MySQL is an open-source database so you don't have to pay a single penny to use
it.
MySQL is a very powerful program so it can handle a large set of functionality of
the most expensive and powerful database packages.
MySQL is customizable because it is an open source database and the open-
source GPL license facilitates programmers to modify the SQL software according
to their own specic environment.
MySQL is quicker than other databases so it can work well even with the large
data set.
MySQL supports many operating systems with many languages like PHP, PERL, C,
C++, JAVA, etc.
MySQL uses a standard form of the well-known SQL data language.
MySQL is very friendly with PHP, the most popular language for web development.
MySQL supports large databases, up to 50 million rows or more in a table. The
default le size limit for a table is 4GB, but you can increase this (if your operating
system can handle it) to a theoretical limit of 8 million terabytes (TB).
Syntax to access MySQL with Python:
import mysql.connector
db_connection = mysql.connector.connect(
host="hostname",
user="username",
passwd="password"
)
Performing Transactions
Transactions are a mechanism that ensures data consistency. Transactions have
the following four properties
Atomicity Either a transaction completes or nothing happens at all.
Consistency A transaction must start in a consistent state and leave the system in a
consistent state.
Isolation Intermediate results of a transaction are not visible outside the current
transaction.
Durability Once a transaction was committed, the effects are persistent, even after a
system failure.
The Python DB API 2.0 provides two methods to either commit or rollback a
transaction.
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
pf3

Partial preview of the text

Download MySQL: The Popular Open-Source Relational Database and more Lecture notes Database Management Systems (DBMS) in PDF only on Docsity!

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:

  • MySQL is an open-source database so you don't have to pay a single penny to use it.
  • (^) MySQL is a very powerful program so it can handle a large set of functionality of the most expensive and powerful database packages.
  • MySQL is customizable because it is an open source database and the open- source GPL license facilitates programmers to modify the SQL software according to their own specific environment.
  • MySQL is quicker than other databases so it can work well even with the large data set.
  • MySQL supports many operating systems with many languages like PHP, PERL, C, C++, JAVA, etc.
  • MySQL uses a standard form of the well-known SQL data language.
  • MySQL is very friendly with PHP, the most popular language for web development.
  • MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes (TB).

Syntax to access MySQL with Python:

import mysql.connector db_connection = mysql.connector.connect( host="hostname", user="username", passwd="password" )

Performing Transactions

Transactions are a mechanism that ensures data consistency. Transactions have

the following four properties −

  • Atomicity − Either a transaction completes or nothing happens at all.
    • Consistency − A transaction must start in a consistent state and leave the system in a

consistent state.

  • Isolation − Intermediate results of a transaction are not visible outside the current

transaction.

  • Durability − Once a transaction was committed, the effects are persistent, even after a

system failure.

The Python DB API 2.0 provides two methods to either commit or rollback a

transaction.

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 | +----+---------------+