From the initial raw mass of data through to a fully functional database application .... a long road with many things to learn. I've run two short MySQL courses
this week, including some coverage of how to access the data they contain from PHP based web pages
and I never cease to amaze myself at how many topics crop up as "must cover before we finish" subjects. I have a habit of writing such topics on the whiteboard during the course so that nothing gets forgotten, and I'm going to share the topics that were on the board yesterday with you to give you an idea of just how wide ranging they are.
My illustrations for this entry are from Bristol Blue Glass
and show the first and last stages in the manufacturing process of a glass cat - from the first ball of molten glass to the addition of the stand.So - what MySQL subjects did I have on my "Must Remember" list on this most recent course?
How to load data that's supplied in the form of text files - perhaps tab or comma separated, and perhaps with various fields encased in quotes, into database tables. The Insert command is great for data for transactions once a system is live, but can be less than ideal for an initial population of tables with heritage data.
Backups of a database are vital - and it's vital you know how to take backups (and to ensure you know how to reload the data too if you need to, but that's another story)
The linking of data that's held in more than one table in order to produce a human-readable view / report. It's also important to know how to join tables based on the contents of a particular field, and how to generate a report that tells you about orphan records in one or other table - records that won't join with just a regular join and can become lost in the system.
If you select from a database, chances are you'll get more than one row in your result set - sometimes a lot more. How do you control the sequence in which the records are returned by your query (i.e. how do you sort your results?)
OK - I admit it, that's an internal code and it's not obvious what I mean by it. It's all to do with PHP programming, though, and ensuring that the programs you write in order to maintain and examine the data base are easy to maintain and robust in operation. It leads me somewhat off the MySQL topics and onto PHP, using a design model that keeps the HTML apart from the business logic, and the structure of the application apart from the "web helper" functions.
Log in to a MySQL database by user name and password, and you'll find that your access rights may also be controlled by the name / IP address of the system that you're seated at. You'll be set up so that there's a whole lot of things you can do over the whole environment managed by MySQL - anything from being allowed to select records through to shutting down the server. And in addition you may be given some rights over individual databases. The further rights "per table" and finally yet more rights "per column". It's vital for the MySQL DBA (Database Administrator) who's setting these up to understand what's what in order that security is not compromised.
. Know your MyISAMs from your heaps from you InnoDb tables. Do you need transaction processing capabilities? Will table locking suffice for your needs or do you need to choose a table type with row locking?
Codd / Normalise
. Codd's principles of database normalisation should be given due weight when you design a database. By ensuring that data doesn't repeat itself, that calculated data is not stored, and that no attempt is made to place two values into a single cell, you'll set yourself up for a robust, long lived and maintainable system even though it might make the tables appear to be pretty unreadable to the human eye at first.
. Default settings for the MySQL daemon and clients can be set up so that individual users don't have to type in long access strings including host and login names each time they want to access their "home" server.
. Where there's a many to many mapping to be defined between two tables, best design principles lead you to create a third table known as a link or pivot table.
. Having taught you how to normalise data, you may then decide that you can go one step beyond that and denormalise it. As long as you know your update rules and think things through very clearly, there can be benefits in denormalising. For example, keep a copy of the current month's data in a "now" table as well as storing the historic data in the main table, or breaking rows across two tables if you have a rarely-required column that account for the majority of the row content.
How to handle large / complex queries from a web front end, where browsers and user's patience is likely to time out before the query is completed.
Where to select and sort
If you're front ending a MySQL enquiry system through PHP, do you do your selection and sorting of data in the database, in the program, or do you use a combination?
. Make sure that special characters such as " and ' and < entered into forms cannot be used to perform injection attacks on the database ... and that they display properly back to the browser when passed from form to variable, variable to table cell, table cell to variable, and back to the browser as part of the HTML response.
Last Insert ID
. How to ensure that new data you add into your tables will join correctly between the tables - finding the automatically generated key and making use of it.
Upgrade - PHP4 to 5 and MySQL4 to 5
. The new password security model in MySQL 4.1 that means that old clients may refuse to connect, and what you can do about it. The new mysqli functions in PHP5, and the unbundling of current MySQL drivers at that release. Things to be aware of in your coding and upgrade plans to make sure that what works on the systems you have today will upgrade easily to the systems you will have tomorrow. (written 2005-11-12, updated 2006-06-05)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesS159 - MySQL 5 and PHP 5 
mysql_connect or mysql_pconnect in PHP? - (2004-10-30) 
MySQL - an FAQ - (2005-12-03) 
MySQL - Password security (authentication protocol) - (2007-04-02) 
What software version do we teach? - (2007-10-31) 
Connecting to MySQL 5 from PHP on Mac OSX Leopard - (2007-12-03) 
Upgrade from PHP 4 to PHP 5 - the TRY issue - (2008-08-15) 
Diagrams to show you how - Tomcat, Java, PHP - (2008-08-22) 
PHP4 v PHP5 - Object Model Difference - (2009-05-11) 
MySQL, MySQLi, PDO or something else - how best to talk to databases from PHP - (2011-09-24)S157 - More MySQL commands 
MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN - (2004-12-20) 
MySQL - Optimising Selects - (2004-12-21) 
Getting a list of unique values from a MySQL column - (2005-04-14) 
Matching in MySQL - (2005-09-24) 
SELECT in MySQL - choosing the rows you want - (2005-11-22) 
MySQL - JOIN or WHERE to link tables correctly? - (2005-12-01) 
An occasional chance, and reducing data to manageable levels - (2005-12-04) 
Combining similar rows from a MySQL database select - (2006-01-17) 
Giving the researcher power over database analysis - (2006-01-22) 
Saving a MySQL query results to your local disc for Excel - (2006-01-29) 
Key facts - SQL and MySQL - (2006-02-04) 
Helicopter views and tartans - (2006-04-06) 
MySQL - the order of clauses and the order of actions - (2007-06-01) 
Outputting numbers as words - MySQL with Perl or PHP - (2007-06-17) 
MySQL joins revisited - (2007-09-03) 
Joining MySQL tables revisited - finding nonmatching records, etc - (2008-03-15) 
Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03) 
Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23) 
MySQL - looking for records in one table that do NOT correspond to records in another table - (2009-03-31) 
Grouping rows for a summary report - MySQL and PHP - (2009-06-27) 
MySQL - efficiency and other topics - (2009-10-10) 
Relating tables with joins in MySQL - (2010-02-21) 
Counting rows in joined MySQL tables - (2010-02-22) 
Optimising and caching your MySQL enquiries - (2010-02-22) 
Removing duplicates from a MySQL table - (2010-02-22) 
Databases - why data is split into separate tables, and how to join them - (2010-11-20) 
SQL - Data v Metadata, and the various stages of data selection - (2011-04-29) 
Extracting data from backups to restore selected rows from MySQL tables - (2015-05-01)S154 - MySQL - Designing an SQL Database System 
MySQL - Pivot tables - (2004-09-22) 
Binary Large Objects or bars - (2005-06-27) 
Oops - I got my initial database design wrong - (2005-07-12) 
Database design - get it right from first principles - (2006-04-02) 
Databases needn't be frightening, hard or expensive - (2006-11-08) 
Display an image from a MySQL database in a web page via PHP - (2006-11-22) 
Code quality counts - (2006-11-26) 
MySQL - table design and initial testing example - (2007-11-06) 
Database design for a shopping application (MySQL) - (2008-03-15) 
More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24) 
What a difference a MySQL Index made - (2009-02-25) 
MySQL - licensing issues, even with using the name - (2009-03-16) 
Images in a database? How big is a database? (MySQL) - (2009-05-28) 
Delegate Question - defining MySQL table relationships as you create the tables - (2010-05-02) 
Blowing our own trumpet - MySQL resources - (2011-07-18) 
Databases - when to treat the rules as guidelines - (2011-10-23) 
FileMaker Day to Unix Time conversion - (2015-02-15)S152 - SQL Primer as Used in MySQL 
NULL in MySQL - (2005-04-06) 
How do I query a database (MySQL)? - (2009-06-15) 
INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables - (2010-11-19) 
Which database should I use? MySQL v SQLite - (2013-02-16)
Some other Articles
Why is Tomcat called Tomcat?I have a river to crossPython printfMore spam - a success storyMySQL - a score of things to rememberRunning a Perl script within a PHP pageNew Navigation Aid - Launch of My WellhoBeing atypical is typicalA new way to get lostWhich MySQL server am I using?