PacktLib: MySQL for Python

MySQL for Python

Credits

About the Author

About the Reviewers

Preface

Getting Up and Running with MySQL for Python

Getting MySQL for Python

Importing MySQL for Python

Connecting with a database

Multiple database connections

Summary

Simple Querying

A brief introduction to CRUD

Forming a query in MySQL

Passing a query to MySQL

Using user-defined variables

Determining characteristics of a database and its tables

Changing queries dynamically

Project: A command-line search utility

Room to grow

Summary

Simple Insertion

Forming a MySQL insertion statement

Helpful ways to nuance an INSERT statement

Passing an insertion through MySQL for Python

Using user-defined variables

Using metadata

Changing insertion values dynamically

Essentials: close and commit

Project: A command-line insertion utility

Summary

Exception Handling

Why errors and warnings are good for you

Errors versus warnings: There's a big difference

The two main errors in MySQLdb

Warnings in MySQL for Python

Handling exceptions passed from MySQL

Catching different types of exceptions

Creating a feedback loop

Project: Bad apples

Summary

Results Record-by-Record

The problem

Why?

How?

Project: A movie database

Summary

Inserting Multiple Entries

The problem

Introducing the executemany() method

executemany(): Basic syntax

executemany(): Behind the scenes

Project: Converting a CSV file to a MySQL table

Summary

Creating and Dropping

Creating databases

Removing or deleting databases

Creating tables

Dropping tables

Doing it in Python

Dropping tables with MySQLdb

Project: Web-based administration of MySQL

Summary

Creating Users and Granting Access

A word on security

Creating users in MySQL

Creating users from Python

Removing users in MySQL

DROPping users in Python

GRANT access in MySQL

Granting access in Python

Removing privileges in MySQL

Using REVOKE in Python

Project: Web-based user administration

Summary

Date and Time Values

Date and time data types in MySQL

Date and time types in Python

Date and time functions

Project: Logging user activity

Summary

Aggregate Functions and Clauses

Calculations in MySQL

Trimming results

Server-side sorting in MySQL

Putting it in Python

Project: Incorporating aggregate functions

Summary

SELECT Alternatives

HAVING clause

Subqueries

Unions

Joins

Doing it in Python

Project: Implement HAVING

Summary

String Functions

Preparing results before their return

Accessing and using index data

Nuancing data

Project: Creating your own functions

Summary

Showing MySQL Metadata

MySQL's system environment

Accessing database metadata

Accessing user metadata

Project: Building a database class

Summary

Disaster Recovery

Every database needs a backup plan

Choosing a backup method

Backing up a database with Python

Summary

Index