MySQL And How Joomla Uses It
Bruce Moore, DEng
Moore Software Services, LLCP.O. Box 183
Coppell, TX 75019(972) 652-0254
www.mooresoftwareservices.com
S i m p l i f y i n g F i n a n c i a l D at a A n a l y s i s
August 11, 2015
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
There are several important notes before we start
Before connecting to the database, create a back up
This lecture won’t talk about commands for inserting, updating anddeleting data
You can mess things up beyond your ability to recoverWill not fit in one hour
Assumes that you have shell access to your web site
Won’t cover configuration that requires root access to server
Won’t cover GUI utilities that require port 3306 to be open
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Akeeba Backup will backup MySQL database and flat files andshould be used before accessing tables
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Akeeba Admin Tools has tool for running table statistics andoptimizing tables. Do this regularly to improve response time.
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the Joomla Global Configuration panel to get the databasename, user ID, and table prefix
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the ’mysql -u username’ command to connect to thedatabase
[a@b ~]$ mysql -u username -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 111939
Server version: 5.5.42-cll MySQL Community Server (GPL)
.
.
.
Type ’help;’ or ’\h’ for help. Type ’\c’ to clear the current input statement.
mysql>
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the MySQL command ’list databases’ to find out the nameof the databases
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| username_joomla3 |
+--------------------+
2 rows in set (0.03 sec)
mysql> use username_joomla3;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the SQL statement ’create user’ to create a non-admin userID
mysql> create user ’noadmin’@’localhost’ identified by ’strong_password’;
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the MySQL command ’show tables’ to find out what tablesare in the database
’abcde’ is where Joomla puts the random prefix to make it harder for attackersto do SQL injection attacks.
mysql> show tables;
+-----------------------------------+
| Tables_in_username_joomla3 |
+-----------------------------------+
| abcde_assets |
| abcde_associations |
| abcde_categories |
| abcde_contact_details |
| abcde_content |
| abcde_content_frontpage |
| abcde_content_rating |
| abcde_content_types |
| abcde_menu |
| abcde_menu_types |
+-----------------------------------+
185 rows in set (0.00 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the MySQL ’show columns’ command to list the columnsin the CONTENT table
mysql> show columns from edcba_content;
+------------------+---------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+---------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| asset_id | int(10) unsigned | NO | | 0 | |
| title | varchar(255) | NO | | | |
| alias | varchar(255) | NO | | | |
| introtext | mediumtext | NO | | NULL | |
| fulltext | mediumtext | NO | | NULL | |
| version | int(10) unsigned | NO | | 1 | |
| metakey | text | NO | | NULL | |
| metadesc | text | NO | | NULL | |
| access | int(10) unsigned | NO | MUL | 0 | |
| hits | int(10) unsigned | NO | | 0 | |
.
.
.
+------------------+---------------------+------+-----+---------------------+----------------+
30 rows in set (0.00 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
A SELECT statement with a calculation will give the hits perday
mysql> select substr(title,1,50),hits/(to_days(now()) - to_days(created))
as hit_rate from edcba_content order by 2 desc;
+----------------------------------------------------+----------+
| substr(title,1,50) | hit_rate |
+----------------------------------------------------+----------+
| Social-buttons.com Referral Spam | 87.4326 |
| 100dollars-seo.com Referral Spam | 58.6393 |
| Stopping Rachel from Cardholder Services | 17.2479 |
| Videos-for-your-business.com Google Analytics Refe | 14.7500 |
| Success-seo.com Referral Spam | 14.0000 |
| Sales and Lead Management with SuiteCRM | 13.7710 |
| Effective Interest (Yield) Loan Fee Amortization | 13.7235 |
| Email Security Part 1: Verifying an Email Sender’ | 13.7163 |
...
+----------------------------------------------------+----------+
63 rows in set (0.00 sec)MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use an SQL statement to find the articles that use MathJax
mysql> select title from edcba_content where edcba_content.introtext
like ’%mathjax%’;
+-------------------------------------------------------------+
| title |
+-------------------------------------------------------------+
| Calculating the Marginal Cost of Funds for Deposit Pricing |
| Effective Interest (Yield) Loan Fee Amortization |
| Configuring Server Side Page Caching in Joomla |
| Effective Interest (Yield) Loan Discount Points Application |
| Estimating the Cost of Funds for Loan Pricing |
| Opting Out of Browser Tracking |
+-------------------------------------------------------------+
6 rows in set (0.01 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use an SQL statement to find all articles that reference a script
mysql> select title from edcba_content where edcba_content.introtext
like ’%<script%’;
+-------------------------------------------------------------+
| title |
+-------------------------------------------------------------+
| About |
| Contact |
| Calculating the Marginal Cost of Funds for Deposit Pricing |
| Effective Interest (Yield) Loan Fee Amortization |
| Estimating the Cost of Funds for Loan Pricing |
| Social-buttons.com Referral Spam |
...
+-------------------------------------------------------------+
16 rows in set (0.01 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use an SQL statement to find out what Joomla tags are mostfrequently used.
mysql> select title,hits from edcba_tags order by hits desc;
+----------------------------+------+
| title | hits |
+----------------------------+------+
| Security | 669 |
| Loans | 651 |
| Open Source | 627 |
| Amortization | 585 |
| Yield | 582 |
| Marginal Cost | 556 |
| Email | 550 |
...
+----------------------------+------+
37 rows in set (0.00 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the MySQL ’show databases’ and ’use information schema’commands to look at the database catalog tables
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| username_joomla3 |
+--------------------+
2 rows in set (0.00 sec)
mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use the MySQL show tables command to look at the tables inthe catalog
mysql> show tables;
+---------------------------------------+
| Tables_in_information_schema |
+---------------------------------------+
| CLIENT_STATISTICS |
| COLUMNS |
| INDEX_STATISTICS |
| STATISTICS |
| TABLES |
| TABLESPACES |
| TABLE_STATISTICS |
...
+---------------------------------------+
45 rows in set (0.00 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
To find out the number of rows in a table use an SQL statement
mysql> select table_name,table_rows from tables
where table_name like ’edcba%’ order by table_rows desc;
+-----------------------------------+------------+
| table_name | table_rows |
+-----------------------------------+------------+
| edcba_sh404sef_urls | 2275 |
| edcba_redirect_links | 1723 |
| edcba_finder_links_terms3 | 1301 |
| edcba_sh404sef_aliases | 820 |
| edcba_content | 31 |
| edcba_tags | 27 |
...
+-----------------------------------+------------+
100 rows in set (2.88 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
But we know that there are more than 60 articles in thecontent table...why only 31 here?
The number of rows is populated when you run statistics on a table; this isused to determine the access path.
The indexes and access path will change based upon table statistics
Old statistics may cause poor performance.
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
But we know that there are more than 60 articles in thecontent table...why only 31 here?
The number of rows is populated when you run statistics on a table; this isused to determine the access path.
The indexes and access path will change based upon table statistics
Old statistics may cause poor performance.
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
But we know that there are more than 60 articles in thecontent table...why only 31 here?
The number of rows is populated when you run statistics on a table; this isused to determine the access path.
The indexes and access path will change based upon table statistics
Old statistics may cause poor performance.
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
But we know that there are more than 60 articles in thecontent table...why only 31 here?
The number of rows is populated when you run statistics on a table; this isused to determine the access path.
The indexes and access path will change based upon table statistics
Old statistics may cause poor performance.
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Akeeba Admin Tools has a tool for running table statistics andoptimizing tables
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
You can also use MySQL commands to optimize all tables in aninstallation
mysqlcheck -u username -p -o --all-databases
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Use a SELECT statement to look at the row counts
mysql> select table_name,table_rows from tables
where table_name like ’edcba%’
order by table_rows desc;
+-----------------------------------+------------+
| table_name | table_rows |
+-----------------------------------+------------+
| edcba_sh404sef_urls | 2275 |
| edcba_redirect_links | 2128 |
| edcba_finder_links_terms3 | 1123 |
| edcba_sh404sef_aliases | 820 |
| edcba_content | 54 |
| edcba_tags | 49 |
...
+-----------------------------------+------------+
100 rows in set (0.56 sec)MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
The query cache statistics are available through ’show status’
mysql> show status like ’qcache%’;
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1135 |
| Qcache_free_memory | 28564064 |
| Qcache_hits | 1125029 |
| Qcache_inserts | 314387 |
| Qcache_lowmem_prunes | 37134 |
| Qcache_not_cached | 63037 |
| Qcache_queries_in_cache | 1160 |
| Qcache_total_blocks | 3698 |
+-------------------------+----------+
8 rows in set (0.00 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Akeeba Backup will backup MySQL database and flat files andshould be used before accessing tables
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
The mysqldump command creates a file with all of the SQLneeded to recreate the database
[a@b ~]$ mysqldump -u username_joomla -p --all-databases > mysqldump_2015_08_10.dmp
Enter password:
[a@b ~]$ ls -lh *.dmp
-rw-rw-r-- 1 username username 57M Aug 10 12:17 mysqldump_2015_08_10.dmp
[a@b ~]$ gzip *.dmp
[a@b ~]$ ls -lh *.dmp.gz
-rw-rw-r-- 1 username username 18M Aug 10 12:17 mysqldump_2015_08_10.dmp.gz
[a@b ~]$
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
MySQL comes with two different ’engines’ (InnoDB andMyISAM’ and allows others
mysql> select table_name, engine, table_rows from tables
where table_name like ’edcba%’ order by engine,table_rows desc;
+-----------------------------------+--------+------------+
| table_name | engine | table_rows |
+-----------------------------------+--------+------------+
| edcba_finder_terms | InnoDB | 97119 |
...
| edcba_content | InnoDB | 54 |
...
| edcba_finder_tokens_aggregate | MEMORY | 0 |
...
| edcba_admintools_scanalerts | MyISAM | 15783 |
+-----------------------------------+--------+------------+
100 rows in set (0.42 sec)
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
InnoDB is newer and has better performance in manysituations, but uses much more memory
MyISAM is the default engine
InnoDB is newer, has more granular locking and is frequently faster thanMyISAM but uses much more memory
MEMORY is not recoverable...used only for fast access
Some extensions have a lot of rows
Joomla ’finder’ function is new search toolSh404sef extension can have many rows to handle multiple URLs
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
InnoDB is newer and has better performance in manysituations, but uses much more memory
MyISAM is the default engine
InnoDB is newer, has more granular locking and is frequently faster thanMyISAM but uses much more memory
MEMORY is not recoverable...used only for fast access
Some extensions have a lot of rows
Joomla ’finder’ function is new search toolSh404sef extension can have many rows to handle multiple URLs
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
InnoDB is newer and has better performance in manysituations, but uses much more memory
MyISAM is the default engine
InnoDB is newer, has more granular locking and is frequently faster thanMyISAM but uses much more memory
MEMORY is not recoverable...used only for fast access
Some extensions have a lot of rows
Joomla ’finder’ function is new search toolSh404sef extension can have many rows to handle multiple URLs
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
InnoDB is newer and has better performance in manysituations, but uses much more memory
MyISAM is the default engine
InnoDB is newer, has more granular locking and is frequently faster thanMyISAM but uses much more memory
MEMORY is not recoverable...used only for fast access
Some extensions have a lot of rows
Joomla ’finder’ function is new search toolSh404sef extension can have many rows to handle multiple URLs
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
InnoDB is newer and has better performance in manysituations, but uses much more memory
MyISAM is the default engine
InnoDB is newer, has more granular locking and is frequently faster thanMyISAM but uses much more memory
MEMORY is not recoverable...used only for fast access
Some extensions have a lot of rows
Joomla ’finder’ function is new search toolSh404sef extension can have many rows to handle multiple URLs
MySQL Bruce Moore
MySQL
BruceMoore
Housekeeping
AkeebaUtilities
SQLQueries
Backup
Engines
Contact information
Bruce Moore, [email protected](972) 652-0254
MySQL Bruce Moore