Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
MySQL for Python

You're reading from   MySQL for Python Integrating MySQL and Python can bring a whole new level of productivity to your applications. This practical tutorial shows you how with examples and explanations that clarify even the most difficult concepts.

Arrow left icon
Product type Paperback
Published in Sep 2010
Publisher Packt
ISBN-13 9781849510189
Length 440 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Albert Lukaszewski Albert Lukaszewski
Author Profile Icon Albert Lukaszewski
Albert Lukaszewski
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

MySQL for Python
Credits
About the Author
About the Reviewers
Preface
1. Getting Up and Running with MySQL for Python FREE CHAPTER 2. Simple Querying 3. Simple Insertion 4. Exception Handling 5. Results Record-by-Record 6. Inserting Multiple Entries 7. Creating and Dropping 8. Creating Users and Granting Access 9. Date and Time Values 10. Aggregate Functions and Clauses 11. SELECT Alternatives 12. String Functions 13. Showing MySQL Metadata 14. Disaster Recovery Index

Index

A

  • * (asterisk), MySQL statements
    • about / * (asterisk)
  • access, granting in MySQL
    • about / GRANT access in MySQL
    • GRANT statement / The GRANT statement in MySQL
    • GRANT, using with REQUIRE clause / Using REQUIREments of access
    • WITH clause, using / Using a WITH clause
  • ADDDATE() function / Date and time functions
  • ADDTIME() function / Date and time functions
  • add_option() method / Specifying the search term from the command-line
  • ARCHIVE
    • about / ENGINE
  • AVG() function
    • about / AVG()
    • mean / Mean
    • median / Median
    • mode / Mode

B

  • backup method
    • selecting / Choosing a backup method
    • table files, copying / Copying the table files
    • delimited backups / Delimited backups within MySQL
    • archiving from command line / Archiving from the command line
  • bad apples project
    • about / Project: Bad apples
    • connection() function / Project: Bad apples
    • sendmail() function / Project: Bad apples
    • preamble / The preamble
    • connection, making / Making the connection
    • error messages, sending / Sending error messages
    • main() function / The main() thing
  • basic menu, web-based administration project
    • authorization details / Authorization details
    • operational sections / Three operational sections of the dialogue
    • variables / The variables
  • BLACKHOLE
    • about / ENGINE

C

  • calculations, in MySQL
    • about / Calculations in MySQL
    • functions, used / Calculations in MySQL
    • COUNT() function / COUNT()
    • SUM() function / SUM()
    • MAX() function / MAX()
    • MIN() function / MIN()
    • AVG() function / AVG()
  • capitalise() function
    • about / Capitalise()
    • DELIMITER / DELIMITER
    • function definition / The function definition
    • calling / Calling the function
    • defining, in Python / Defining the function in Python
    • defining, as Python value / Defining the function as a Python value
    • MySQL function, sourcing as Python module / Sourcing the MySQL function as a Python module
    • sourcing, as MySQL code / Sourcing the function as MySQL code
  • Capitalise() function / CREATE (DATABASE/FUNCTION/PROCEDURE/TABLE/VIEW)
  • close command
    • about / In need of some closure
  • collation / Specifying the collation for a database
  • command-line insertion utility
    • about / Project: A command-line insertion utility
    • modules, required / The necessary modules
    • main() function / The main() thing
    • other functions, coding / Coding the other functions
    • main(), calling / Calling main()
  • command-line programs
    • mysqldump / mysqldump
    • mysqlhotcopy / mysqlhotcopy
  • command-line search utility
    • about / Project: A command-line search utility
    • database, preparing for search / Preparing a database for searching
    • work plan, implementing / Planning your work, then working your plan, Develop a well-abstracted search functionality
    • work, planning / Planning your work, then working your plan
    • search term, specifying / Specifying the search term from the command-line
    • -o funtion, implementing / Implementing and incorporating the other functions: -t, -f, and -o
    • -f funtion, implementing / Implementing and incorporating the other functions: -t, -f, and -o
    • -t funtion, implementing / Implementing and incorporating the other functions: -t, -f, and -o
    • output file option, including / Including an option for an output file
  • commit command
    • about / What happened to commit?
  • commit method / Closing the connection
  • Computer Emergency Response Team (CERT) / Why errors and warnings are good for you
  • computing resources
    • about / Computing resources
    • local resources / Local resources
    • web applications / Web applications
  • CONCAT() function
    • about / CONCAT() function
  • connect() function / Creating a connection object
  • Connect() function / MySQLdb
  • connect() method / The log framework
  • Connect function / MySQLdb
  • Connection() function / MySQLdb
  • connection() function, web-based administration project
    • code / Connecting with a database
  • CONVERT_TZ() function / Date and time functions
  • COUNT() function
    • about / COUNT()
  • creating custom functions project
    • about / Project: Creating your own functions
    • Hello() function, creating / Hello()
    • capitalise() function, creating / Capitalise()
  • CROSS joins / CROSS joins
  • CRUD
    • about / A brief introduction to CRUD
  • CSV
    • about / ENGINE
  • CSV file
    • about / Project: Converting a CSV file to a MySQL table
  • CSV file to MySQL table conversion project
    • about / Project: Converting a CSV file to a MySQL table
    • preamble / The preamble
    • options / The options
    • connection object, creating / Defining the connection
    • convert, creating / Creating convert
    • main() function / The main() function
    • main() function, calling / Calling main()
  • CURDATE() function / Date and time functions, CURDATE()
  • CURRENT_DATE() function / Date and time functions
  • CURRENT_TIME() function / Date and time functions
  • CURRENT_TIMESTAMP() function / Date and time functions
  • cursor() method / Creating a cursor object
  • Cursor.executemany() method / executemany(): multiple SELECT statements
  • CURTIME() function / Date and time functions, CURTIME()
  • customized exception handling
    • about / Customizing for catching
    • one type of exception, catching / Catching one type of exception
    • different exceptions, catching / Catching different exceptions
    • combined catching / Combined catching of exceptions
    • different exceptions, handling / Raising different exceptions

D

  • data, inserting through MySQL
    • about / Passing an insertion through MySQL for Python
    • preliminaries, setting up / Setting up the preliminaries
    • simple INSERT statement / A simple INSERT statement
    • complex INSERT commands / More complex INSERT commands
  • database characteristics
    • determining / Determining characteristics of a database and its tables
    • tables, determining / Determining what tables exist
    • table number, assigning / Assigning each table a number
    • options, offering to user / Offering the options to the user
    • detail search query, allowing / Allowing the user to detail a search query
  • database class
    • building / Project: Building a database class
    • writing / Writing the class
    • fetchquery() method, defining / Defining fetchquery() and some core methods
    • table structure, retrieving / Retrieving table status and structure
    • table status, retrieving / Retrieving table status and structure
    • CREATE statements, retrieving / Retrieving the CREATE statements
    • main() function, defining / Define main()—part 1
    • resproc() method, writing / Writing resproc()
    • variables / Modules and variables
    • modules / Modules and variables
    • login and USE statements / Login and USE
  • database connection, through MySQL for Python
    • creating / Connecting with a database
    • connection object, creating / Creating a connection object
    • cursor object, creating / Creating a cursor object
    • database, interacting with / Interacting with the database
    • connection, closing / Closing the connection
  • DatabaseError
    • about / DatabaseError
  • database metadata
    • accessing / Accessing database metadata
    • DATABASES / DATABASES
    • USE command, using / Using the USE command
    • table-oriented operations / Accessing metadata about tables
    • FUNCTION STATUS, using / FUNCTION STATUS
  • databases, creating in MySQL
    • about / Creating databases, Test first, create second
    • specifications, creating / CREATE specifications
    • default character set, specifying / Specifying the default character set
    • collation, specifying / Specifying the collation for a database
    • collation, declaring / Declaring collation
    • default collations, finding / Finding available character sets and collations
    • character sets, finding / Finding available character sets and collations
  • databases, creating with MySQLdb
    • about / Creating databases with MySQLdb
    • output, testing / Testing the output
    • CREATE statement, configuring / Dynamically configuring the CREATE statement
  • databases, deleting in MySQL
    • about / Removing or deleting databases
    • errors, avoiding / Avoiding errors
    • database, dropping / Preventing (illegal) access after a DROP
  • DataError
    • about / DataError
  • data piecemeal retrieval
    • MySQL used / How?
    • fetchone() method / The fetchone() method
    • fetchmany() method / The fetchmany() method
  • data receiving, web-based administration project
    • CGI, used / Using CGI
    • PHP, used / Using PHP
  • data types, MySQL
    • TIME / Date and time data types in MySQL, TIME
    • TIMESTAMP / Date and time data types in MySQL, TIMESTAMP
    • DATE / Date and time data types in MySQL, DATE
    • DATETIME / Date and time data types in MySQL, DATETIME
    • YEAR / Date and time data types in MySQL, YEAR
  • DATE() function / Date and time functions, DATE()
  • date and time-related functions, MySQL
    • about / Date and time functions
    • ADDDATE() / Date and time functions
    • ADDTIME() / Date and time functions
    • CONVERT_TZ() / Date and time functions
    • CURDATE() / Date and time functions, CURDATE()
    • CURRENT_DATE() / Date and time functions
    • CURRENT_TIME() / Date and time functions
    • CURRENT_TIMESTAMP() / Date and time functions
    • CURTIME() / Date and time functions, CURTIME()
    • DATE_ADD() / Date and time functions
    • DATE_FORMAT() / Date and time functions
    • DATE_SUB() / Date and time functions
    • DATE() / Date and time functions, DATE()
    • DATEDIFF() / Date and time functions, DATEDIFF()
    • DAY() / Date and time functions
    • DAYNAME() / Date and time functions
    • DAYOFMONTH() / Date and time functions
    • DAYOFWEEK() / Date and time functions
    • DAYOFYEAR() / Date and time functions
    • EXTRACT / Date and time functions
    • FROM_DAYS() / Date and time functions
    • FROM_UNIXTIME() / Date and time functions
    • GET_FORMAT() / Date and time functions
    • HOUR() / Date and time functions
    • LAST_DAY / Date and time functions
    • LOCALTIME() / Date and time functions
    • LOCALTIMESTAMP() / Date and time functions
    • MAKEDATE() / Date and time functions
    • MAKETIME() / Date and time functions
    • MICROSECOND() / Date and time functions
    • MINUTE() / Date and time functions
    • MONTH() / Date and time functions
    • MONTHNAME() / Date and time functions
    • NOW() / Date and time functions
    • PERIOD_ADD() / Date and time functions
    • PERIOD_DIFF() / Date and time functions
    • QUARTER() / Date and time functions
    • SEC_TO_TIME() / Date and time functions
    • SECOND() / Date and time functions
    • STR_TO_DATE() / Date and time functions
    • SUBDATE() / Date and time functions
    • SUBTIME() / Date and time functions
    • SYSDATE() / Date and time functions
    • TIME_FORMAT() / Date and time functions
    • TIME_TO_SEC() / Date and time functions
    • TIME() / Date and time functions, TIME()
    • TIMEDIFF() / Date and time functions
    • TIMESTAMP() / Date and time functions
    • TIMESTAMPADD() / Date and time functions
    • TIMESTAMPDIFF() / Date and time functions
    • TO_DAYS() / Date and time functions
    • TO_SECONDS() / Date and time functions
    • UNIX_TIMESTAMP() / Date and time functions
    • UTC_DATE() / Date and time functions
    • UTC_TIME() / Date and time functions
    • UTC_TIMESTAMP() / Date and time functions
    • WEEK() / Date and time functions
    • WEEKDAY() / Date and time functions
    • WEEKOFYEAR() / Date and time functions
    • YEAR() / Date and time functions
    • YEARWEEK() / Date and time functions
    • NOW() function / NOW()
    • EXTRACT() / EXTRACT()
  • DATE data type, MySQL
    • about / DATE
    • output formats / Output and Input formats
    • input range / Input range
  • DATEDIFF() function / Date and time functions, DATEDIFF()
  • DATETIME data type, MySQL
    • about / DATETIME
    • output format / Output format
    • input formats / Input formats
    • input range / Input range
    • using, in CREATE statement / Using DATETIME in a CREATE statement
  • DATE_ADD() function / Date and time functions, DATE_SUB() and DATE_ADD()
  • DATE_FORMAT() function / Date and time functions, DATE_FORMAT()
  • DATE_SUB() function / Date and time functions, DATE_SUB() and DATE_ADD()
  • DAY() function / Date and time functions
  • DAYNAME() function / Date and time functions
  • DAYOFMONTH() function / Date and time functions
  • DAYOFWEEK() function / Date and time functions
  • DAYOFYEAR() function / Date and time functions
  • dbaction() function / Planning the functions
  • dbaction() function, web-based administration project
    • code / Database action
  • DBAPISet / MySQLdb
  • Debian package manager
    • about / Using apt tools on Debian-like systems
  • delimited backups
    • about / Delimited backups within MySQL
    • SELECT INTO OUTFILE, using to export data / Using SELECT INTO OUTFILE to export data
    • LOAD DATA INFILE, using to import data / Using LOAD DATA INFILE to import data
  • DISTINCT function
    • about / DISTINCT
  • dropdb() function / Planning the functions

E

  • Easy Install
    • about / Installing egg handling software
  • easy_install tool
    • about / Using a package manager (Linux)
  • egg-info directory / Installing MySQL for Python from an egg file
  • egg file
    • about / Using an egg file
  • egg handling software
    • installing / Installing egg handling software
  • end-of-request signal / Web applications
  • engine
    • specifying / Specifying the engine
  • ENGINE command
    • about / ENGINE
  • ENGINE status
    • about / ENGINE status
  • errors
    • benefits / Why errors and warnings are good for you
    • versus, warnings / Errors versus warnings: There's a big difference
  • error types
    • DataError / DataError
    • IntegrityError / IntegrityError
    • InternalError / InternalError
    • NotSupportedError / NotSupportedError
    • OperationalError / OperationalError
    • ProgrammingError / ProgrammingError
  • exceptions handling
    • about / Handling exceptions passed from MySQL
    • Python exception-handling / Python exception-handling
    • exception, catching from MySQLdb / Catching an exception from MySQLdb
    • error or warning, raising / Raising an error or a warning
    • exceptions, making less intimidating / Making exceptions less intimidating
  • execute() function / Planning the functions, Ensure logging occurs
  • execute() function, web-based administration project
    • code / execute()
  • execute() method / A simple SELECT statement, Project: Bad apples
  • executemany() method
    • about / Introducing the executemany() method
    • basic syntax / executemany(): Basic syntax
    • multiple INSERT statements / executemany(): Multiple INSERT statements
    • multiple SELECT statements / executemany(): multiple SELECT statements
    • process / executemany(): Behind the scenes
    • underlying code / executemany(): Behind the scenes
    • command-line option configuration / Command-line option configuration
    • configuration file, using / Using a configuration file
    • 16 MB required / More than 16 MB is often unnecessary
  • EXTRACT function / Date and time functions, EXTRACT()

F

  • FEDERATED
    • about / ENGINE
  • feedback loop
    • creating / Creating a feedback loop
  • fetchall() / Querying the database for its structure
  • fetchall() method / A simple SELECT statement
  • fetchmany() method
    • about / The fetchmany() method
  • fetchone() method
    • about / The fetchone() method
  • Filemaker Pro / Local resources
  • files, copying from MySQL
    • about / Copying the table files
    • locking / Locking and flushing
    • LOCK TABLES command / LOCK TABLES
    • FLUSH command / FLUSH
    • tables, unlocking / Unlocking the tables
    • data, restoring / Restoring the data
  • first-in first-out (FIFO) queue system / Web applications
  • for loop
    • about / The for loop
  • form() method / Project: Bad apples
  • FORMAT() function
    • about / FORMAT()
  • FROM, MySQL statements
    • about / FROM
  • FROM_DAYS() function / Date and time functions
  • FROM_UNIXTIME() function / Date and time functions
  • function codes, web-based administration project
    • connecting without a database / Connecting without a database
    • connecting with a database / Connecting with a database
    • database action / Database action
    • table action / Table action
    • query action / Query action
    • execute() / execute()

G

  • generators
    • about / Generators
    • creating, fetchone() used / Using fetchone() in a generator
    • fetchmany(), using / Using fetchmany() in a generator
  • getopt module / Specifying the search term from the command-line
  • GET_FORMAT() function / Date and time functions
  • GROUP BY, MySQL statements
    • about / GROUP BY
  • GROUP BY clause
    • about / GROUP BY
  • GROUP_CONCAT() function
    • working / GROUP_CONCAT()
    • about / GROUP_CONCAT()
    • delimiter, specifying / Specifying the delimiter
    • maximum length, customizing / Customizing the maximum length
    • using, with DISTINCT / Using GROUP_CONCAT() with DISTINCT

H

  • HAVING, MySQL statements
    • about / HAVING
  • HAVING clause
    • about / HAVING clause
    • subqueries / Subqueries
    • unions / Unions
    • joins / Joins
  • HAVING implementation
    • about / Project: Implement HAVING , RHAVING implementationaboutevising the Python backend
    • Python backend, revising / RHAVING implementationaboutevising the Python backend
    • qaction() function, revising / Revising qaction()
    • main() function, revising / Revising main()
    • options, revising / Revising the options
    • HTML interface, revising / Revising the HTML interface
  • Hello() function
    • creating / Hello()
  • help() function / Accessing online help when you need it, Specifying the search term from the command-line
  • HOUR() function / Date and time functions
  • HTML output, web-based administration project
    • about / The HTML output
    • definition / Basic definition
    • message attribute / The message attribute
    • header() method, defining / Defining header()
    • footer() method, defining / Defining footer()
    • body() method, defining / Defining body()
    • page() method, defining / Defining page()
  • HTTP persistent connections / Web applications

I

  • IBMDBI
    • about / ENGINE
  • incorporating aggregate functions project
    • about / Project: Incorporating aggregate functions
    • qaction() function, adding / Adding to qaction()
    • main() function, revising / Revising main()
    • options, setting up / Setting up the options
    • HTML form, changing / Changing the HTML form
  • INNER joins / INNER joins
  • InnoDB
    • about / ENGINE
  • INSERT() function
    • about / INSERT()
  • insertion values, changing
    • about / Changing insertion values dynamically
    • name value, validating / Validating the value of name
    • price value, validating / Validating the value of price
    • user, querying / Querying the user for a correction
    • fish and price, passing for validation / Passing fish and price for validation
  • INSERT statement, processing ways
    • about / Helpful ways to nuance an INSERT statement
    • INSERT...SELECT... / INSERT...SELECT...
    • INSERT DELAYED… / INSERT DELAYED…
    • INSERT...ON DUPLICATE KEY UPDATE... / INSERT...ON DUPLICATE KEY UPDATE...
  • INSTR() function
    • about / INSTR()
  • int() function / Querying the database for its structure
  • IntegrityError
    • about / IntegrityError
  • InterfaceError
    • about / InterfaceError
  • InternalError
    • about / InternalError
  • INTO OUTFILE, MySQL statements
    • about / INTO OUTFILE
  • isdigit() method / Querying the database for its structure
  • iterate
    • drawbacks / Why not iterate?
  • iteration
    • about / Iteration: What is it?
  • iterative loops
    • generating / Generating loops
    • while...if loops / while...if loops
    • for loop / The for loop
  • iterators
    • about / Iterators
    • function / Illustrative iteration

J

  • joins, HAVING clause
    • about / Joins
    • RIGHT joins / LEFT and RIGHT joins
    • LEFT joins / LEFT and RIGHT joins
    • OUTER joins / OUTER joins
    • INNER joins / INNER joins
    • NATURAL joins / NATURAL joins
    • CROSS joins / CROSS joins

L

  • LAST_DAY function / Date and time functions
  • LEFT joins / LEFT and RIGHT joins
  • len() function / Querying the database for its structure
  • LENGTH() function
    • about / LENGTH()
  • LIMIT, MySQL statements
    • about / LIMIT
  • limitations, iterate
    • prime numbers generation, test sample / A test sample: Generating primes
    • test sample / A test sample: Generating primes
    • execution speeds, comparing / Comparing execution speeds
  • limitations, MySQL script
    • lack of automation / Lack of automation
    • unscheduled debugging process / Debugging the process
    • inefficient I/O / Inefficient I/O
  • live backups
    • about / Live backups
  • LOCALTIME() function / Date and time functions
  • LOCALTIMESTAMP() function / Date and time functions
  • LOCATE() function
    • about / LOCATE()
  • logdb / The log framework
  • logging user activity project
    • about / Project: Logging user activity, The log framework, The logger() function
    • database, creating / Creating the database
    • table, creating / Creating the table
    • INSERT statement, forming / Forming the INSERT statement, Ensure logging occurs
  • LOWER() function
    • about / LOWER()

M

  • main() function, bad apples project
    • about / The main() thing
    • actions / Try, try again
  • main() function, command-line insertion utility
    • about / The main() thing
    • flag system, coding / Coding the flag system
    • values, testing / Testing the values passed by the user
    • database connection, establishing / Try to establish a database connection
    • tables, displaying / Showing the tables
    • tables structure, displaying / Showing the table structure, if desired
    • user input, accepting / Accepting user input for the INSERT statement
    • INSERT statement, building / Building the INSERT statement from the user input and executing it
    • connection, closing / Committing changes and closing the connection
    • changes, committing / Committing changes and closing the connection
    • calling / Calling main()
  • main function, movie database project
    • about / The main() thing
    • calling / Calling main()
  • MAKEDATE() function / Date and time functions
  • MAKETIME() function / Date and time functions
  • MAX() function
    • about / MAX()
  • MEMORY
    • about / ENGINE
  • MERGE
    • about / ENGINE
  • metacharacters, MySQL
    • . / * (asterisk)
    • ? / * (asterisk)
    • * / * (asterisk)
    • + / * (asterisk)
    • {n} / * (asterisk)
    • {m,n} / * (asterisk)
    • {n,} / * (asterisk)
    • ^ / * (asterisk)
    • $ / * (asterisk)
    • [[*<*]] / * (asterisk)
    • [[*>*]] / * (asterisk)
    • [*class*] / * (asterisk)
    • [*alpha*] / * (asterisk)
    • [*space*] / * (asterisk)
    • [*punct*] / * (asterisk)
    • [*upper*] / * (asterisk)
    • [abc] / * (asterisk)
    • [^xyz] / * (asterisk)
    • | / * (asterisk)
  • metadata, MySQL insertion statement
    • database, querying / Querying the database for its structure
    • table structure, retrieving / Retrieving the table structure
  • MICROSECOND() function / Date and time functions
  • MID() function
    • about / SUBSTRING() or MID()
  • MIN() function
    • about / MIN()
  • MINUTE() function / Date and time functions
  • MONTH() function / Date and time functions
  • MONTHNAME() function / Date and time functions
  • movie database project
    • about / Project: A movie database
    • Sakila, downloading / Getting Sakila
    • Sakila database, creating / Creating the Sakila database
    • Sakila database structure / The structure of Sakila
    • Sakila database, planning / Planning it out
    • SQL statements used / The SQL statements to be used
    • user data, accepting / Accepting user data
    • MySQLQuery class, implementing / A MySQL query with class
    • results, formatting / Formatting the results
    • sample, formatting / Formatting a sample
    • result sets, formatting / Formatting a larger set of results
    • main() function / The main() thing
    • main() function, calling / Calling main()
    • running / Running it
  • multiple database connection, through MySQL for Python
    • about / Multiple database connections
  • multiple items, inserting
    • issues / The problem
  • MyISAM database engine
    • about / ENGINE
  • MySQL
    • query, forming / Forming a query in MySQL
    • query, passing to / Passing a query to MySQL
    • insertion, passing / Passing an insertion through MySQL for Python
    • databases, creating / Creating databases
    • databases, removing/deleting / Removing or deleting databases
    • tables, creating / Creating tables
    • tables, dropping / Dropping tables
    • users, creating / Creating users in MySQL
    • access, granting / GRANT access in MySQL
    • privileges, removing / Removing privileges in MySQL
    • data types / Date and time data types in MySQL
    • date and time-related functions / Date and time functions
    • calculations / Calculations in MySQL
    • results, trimming / Trimming results
    • server-side sorting / Server-side sorting in MySQL
    • system environment / MySQL's system environment
  • MySQL, for Python
    • getting / Getting MySQL for Python
    • getting, package manager used / Using a package manager (only on Linux)
    • getting, RPMs and yum used / Using RPMs and yum
    • getting, RPMs and urpm used / Using RPMs and urpm
    • getting, apt tools using on Debian-like systems / Using apt tools on Debian-like systems
    • getting, installer used for windows / Using an installer for Windows
    • getting, egg file used / Using an egg file
    • getting, tarball used / Using a tarball (tar.gz filetar.gz file)
    • importing / Importing MySQL for Python
    • online help, accessing / Accessing online help when you need it
    • MySQLdb, importing / MySQLdb
    • _mysql module / _mysql
    • database, connecting / Connecting with a database
    • multiple database connections / Multiple database connections
    • warning class / Warnings in MySQL for Python
    • exceptions handling / Handling exceptions passed from MySQL
    • error types / Types of errors
  • MySQL C API / Importing MySQL for Python
  • MySQL database
    • backup plan / Every database needs a backup plan
    • offline backups / Offline backups
    • live backups / Live backups
    • backing up, with Python / Backing up a database with Python
  • MySQLdb
    • importing / MySQLdb
    • connection module / MySQLdb
    • cursors module / MySQLdb
    • converters module / MySQLdb
    • times module / MySQLdb
    • errors / The two main errors in MySQLdb
    • DatabaseError / DatabaseError
    • InterfaceError / InterfaceError
  • MySQLdb.connect() / A simple SELECT statement
  • mysqldump
    • about / mysqldump
    • backup file, viewing / Viewing the backup file
    • options / Other options
    • data, restoring / Restoring the data
  • mysqlhotcopy
    • about / mysqlhotcopy
    • options / mysqlhotcopy
  • MySQL insertion statement
    • forming / Forming a MySQL insertion statement
    • INSERT / INSERT
    • INTO / INTO
    • table name / Table name
    • column names / Column names
    • VALUES / VALUES
    • <some values> / <some values>
    • ; (semicolon) / ; (semicolon)
    • user-defined variables, using / Using user-defined variables
    • metadata, using / Using metadata
    • insertion values, changing / Changing insertion values dynamically
  • MySQL queries
    • changing / Changing queries dynamically
    • pattern, matching / Pattern matching in MySQL queries
    • changes, implementing / Putting it into practice
  • MySQLQuery class, movie database project
    • about / A MySQL query with class
    • __init__ method / A MySQL query with class, The __init__ method: The consciousness of the class
    • type / A MySQL query with class
    • connection / A MySQL query with class
    • query / A MySQL query with class
    • execute() / A MySQL query with class
    • format / A MySQL query with class
    • query's type, setting / Setting the query's type
    • cursor, creating / Creating the cursor
    • query, forming / Forming the query
    • query, executing / Executing the query
  • MySQL script
    • drawbacks / Why not a MySQL script?
  • MySQLStatement class, bad apples project
    • writing / The statement class
    • __init__ method / The __init__ method
    • statement type, storing / Storing the statement type
    • statement, forming / Forming the statement
    • statement, executing / Execute the MySQL statement
  • MySQL statements
    • syntactical structure / Forming a query in MySQL
    • SELECT / SELECT
    • * (asterisk) / * (asterisk)
    • FROM / FROM
    • Staff / staff
    • ; (semicolon) / ; (semicolon)
    • WHERE / WHERE
    • GROUP BY / GROUP BY
    • HAVING / HAVING
    • ORDER BY / ORDER BY
    • LIMIT / LIMIT
    • INTO OUTFILE / INTO OUTFILE
  • MySQL statements, movie database project
    • required / The SQL statements to be used
    • films, returning / Returning the films of an actor
    • actors, returning / Returning the actors of a film

N

  • NATURAL joins / NATURAL joins
  • network latency
    • about / Network latency
    • server-client communications / Server-client communications
    • apparent responsiveness / Apparent responsiveness
  • NotSupportedError
    • about / NotSupportedError
  • NOW() function / Date and time functions, NOW()

O

  • offline backups
    • about / Offline backups
  • OperationalError
    • about / OperationalError
  • OptionParser class / Specifying the search term from the command-line
  • optparse module / Specifying the search term from the command-line
  • ORDER BY, MySQL statements
    • about / ORDER BY
  • ORDER BY clause
    • about / ORDER BY
    • universal quantifier, using / Using a universal quantifier
    • alphabetic sorting / Sorting alphabetically or from low-to-high
    • alphabetic sorting, reversing / Reversing the alphabet or sorting high-to-low
    • multiple keys, sorting with / Sorting with multiple keys
  • OUTER joins / OUTER joins

P

  • package manager
    • about / Using a package manager (only on Linux)
  • Pareto's Principle
    • about / Pareto's Principle
  • parse_args() method / Specifying the search term from the command-line
  • PERIOD_ADD() function / Date and time functions
  • PERIOD_DIFF() function / Date and time functions
  • POSIX
    • about / REGEXP
  • POSIX character classes
    • about / REGEXP
  • privileges, removing in MySQL
    • about / Removing privileges in MySQL
    • basic syntax, REVOKE command / Basic syntax
  • profiling, MySQL
    • about / Profiling
    • SHOW PROFILE / SHOW PROFILE
    • SHOW PROFILES / SHOW PROFILES
  • ProgrammingError
    • about / ProgrammingError
  • Python
    • installing, on Windows / On Microsoft Windows, Installing MySQL for Python from an egg file
    • loops, generating / Generating loops
    • iterators / Iterators
    • generators / Generators
    • databases, creating with MySQLdb / Creating databases with MySQLdb
    • access, granting / Granting access in Python
    • REVOKE command, using / Using REVOKE in Python
    • aggregate functions, programming with / Putting it in Python
    • clauses, programming with / Putting it in Python
    • subqueries / Subqueries
    • unions / Unions
    • joins / Joins
  • Python exception-handling
    • about / Python exception-handling
  • Pythons
    • warnings / Why errors and warnings are good for you
    • errors / Why errors and warnings are good for you

Q

  • qaction() function / Planning the functions
    • about / Adding to qaction()
    • new variables, adding / New variables
    • new statement formation / New statement formation
  • QUARTER() function / Date and time functions
  • query
    • forming, in MySQL / Forming a query in MySQL
    • passing, to MySQL / Passing a query to MySQL
  • query() function
    • about / query()
  • query, passing to MySQL
    • about / Passing a query to MySQL
    • simple SELECT statement / A simple SELECT statement
    • results, modifying / Modifying the results

R

  • record-by-record retrieval
    • issue / The problem
    • reasons / Why?
  • record-by-record retrieval, reasons
    • computing resources / Computing resources
    • network latency / Network latency
    • Pareto's Principle / Pareto's Principle
  • REGEXP function
    • about / REGEXP
  • regular expression meta-characters
    • about / REGEXP
  • REPLACE() function
    • about / REPLACE()
  • results trimming, in MySQL
    • DISTINCT function, used / DISTINCT
    • GROUP_CONCAT() function, used / GROUP_CONCAT()
  • REVOKE command
    • using, in Python / Using REVOKE in Python
  • RIGHT joins / LEFT and RIGHT joins
  • ROUND() function
    • about / ROUND()

S

  • ; (semicolon), MySQL statements
    • about / ; (semicolon)
  • Sakila
    • downloading / Getting Sakila
  • Sakila database
    • creating / Creating the Sakila database
    • structure / The structure of Sakila
  • SCUD
    • about / A brief introduction to CRUD
  • SECOND() function / Date and time functions
  • SEC_TO_TIME() function / Date and time functions
  • SELECT, MySQL statements
    • about / SELECT
  • server-side sorting, MySQL
    • about / Server-side sorting in MySQL
    • GROUP BY clause, using / GROUP BY
    • ORDER BY clause, using / ORDER BY
  • setuptools
    • installing / Without a package manager (Mac, Linux)
  • Slashdot effect / Web applications
  • sorting
    • about / New statement formation
  • str() function / Querying the database for its structure
  • string functions, MySQL
    • CONCAT() function / CONCAT() function
    • MID() function / SUBSTRING() or MID()
    • SUBSTRING() function / SUBSTRING() or MID()
    • TRIM() function / TRIM()
    • REPLACE() function / REPLACE()
    • INSERT() functions / INSERT()
    • REGEXP / REGEXP
    • LENGTH() function / LENGTH()
    • INSTR() function / INSTR()
    • LOCATE() function / LOCATE()
    • ROUND() function / ROUND()
    • FORMAT() function / FORMAT()
    • UPPER() function / UPPER()
    • LOWER() function / LOWER()
  • STR_TO_DATE() function / Date and time functions
  • SUBDATE() function / Date and time functions
  • subqueries, HAVING clause
    • about / Subqueries
  • SUBSTRING() function
    • about / SUBSTRING() or MID()
  • SUBTIME() function / Date and time functions
  • SUM() function
    • about / SUM()
  • SYSDATE() function / Date and time functions
  • system environment, MySQL
    • ENGINE command / ENGINE
    • SHOW ENGINES command / SHOW ENGINES
    • profiling / Profiling
    • system variables / SHOW system variables

T

  • table-oriented operations, database metadata
    • about / Accessing metadata about tables
    • tables, displaying / SHOW TABLES
    • table status, displaying / SHOW TABLE STATUS
    • columns, displaying / Showing columns from a table
  • tables, creating in MySQL / Creating tables
    • about / Creating tables
    • bases, covering / Covering our bases
    • errors, avoiding / Avoiding errors
    • temporary tables, creating / Creating temporary tables
  • tables, dropping in MySQL
    • about / Dropping tables
    • errors, avoiding / Avoiding errors
    • user privileges, removing / Removing user privileges
  • tar.gz file / Using a tarball (tar.gz filetar.gz file)
  • tbaction() function / Planning the functions
  • teacup / Local resources
  • TIME() function / Date and time functions, TIME()
  • TIME data type, MySQL
    • about / TIME
    • format / Format, Invalid values, Date and time types in Python
  • TIMEDIFF() function / Date and time functions
  • TIMESTAMP() function / Date and time functions
  • TIMESTAMPADD() function / Date and time functions
  • TIMESTAMP data type, MySQL
    • about / TIMESTAMP
    • input values / Input of values
    • range / Range
    • default value / Defaults, initialization, and updating
    • initialization / Defaults, initialization, and updating
    • updating / Defaults, initialization, and updating
  • TIMESTAMPDIFF() function / Date and time functions
  • TIME_FORMAT() function / Date and time functions
  • TIME_TO_SEC() function / Date and time functions
  • TO_DAYS() function / Date and time functions
  • TO_SECONDS() function / Date and time functions
  • transaction
    • about / Transactions
  • TRIM() function
    • about / TRIM()
    • basic syntax / Basic syntax
    • options / Options
    • alternatives / Alternatives
  • type method / Project: Bad apples

U

  • unions, HAVING clause
    • about / Unions
  • UNIX_TIMESTAMP() function / Date and time functions
  • UPPER() function
    • about / UPPER()
  • urpm package manager
    • about / Using RPMs and urpm
  • user-defined variables
    • using / Using user-defined variables
  • user metadata
    • accessing / Accessing user metadata
    • SHOW GRANTS, using / SHOW GRANTS
    • SHOW PRIVILEGES, using / PRIVILEGES
  • users
    • creating, in MySQL / Creating users in MySQL
    • creating, from Python / Creating users from Python
    • removing, in MySQL / Removing users in MySQL
    • dropping, in Python / DROPping users in Python
  • users, creating in MySQL
    • about / Creating users in MySQL
    • password use, forcing / Forcing the use of a password
    • client host, restricting / Restricting the client's host
  • UTC_DATE() function / Date and time functions
  • UTC_TIME() function / Date and time functions
  • UTC_TIMESTAMP() function / Date and time functions

V

  • valid_digit() function
    • about / valid_digit() and valid_string()
  • valid_string() function
    • about / valid_digit() and valid_string()
  • valid_table() function
    • about / valid_table()

W

  • warnings
    • benefits / Why errors and warnings are good for you
  • web-based administration project
    • functions, planning / Planning the functions
    • function code / Code of each function
    • HTML output / The HTML output
    • data, receiving / Getting the data
    • main() function, defining / Defining main()
  • web-based user administration project
    • about / Project: Web-based user administration
    • new options, in code / New options in the code
    • DROP function, adding / Adding the functions: CREATE and DROP
    • CREATE function, adding / Adding the functions: CREATE and DROP
    • DROP function, adding to main() / Adding CREATE and DROP to main()
    • CREATE function, adding to main() / Adding CREATE and DROP to main()
    • REVOKE function, adding / Adding the functions: GRANT and REVOKE
    • GRANT function, adding / Adding the functions: GRANT and REVOKE
    • GRANT function, adding to main() / Adding GRANT and REVOKE to main()
    • REVOKE function, adding to main() / Adding GRANT and REVOKE to main()
    • testing / Test the program
  • WEEK() function / Date and time functions
  • WEEKDAY() function / Date and time functions
  • WEEKOFYEAR() function / Date and time functions
  • WHERE, MySQL statements
    • about / WHERE
  • WHERE versus HAVING
    • syntax / WHERE versus HAVING: Syntax
    • about / WHERE versus HAVING: Syntax
    • aggregate functions / WHERE versus HAVING: Aggregate functions
    • application / WHERE versus HAVING: Application
  • while...if loops
    • about / while...if loops

Y

  • YEAR() function / Date and time functions
  • YEAR data type, MySQL
    • about / Defaults, initialization, and updating
    • two-digit YEAR value / Two-digit YEAR values
    • four-digit YEAR value / Four-digit YEAR values
    • valid input / Valid input
  • YEARWEEK() function / Date and time functions
  • yum package manager
    • about / Using RPMs and yum
lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime