SlideShare ist ein Scribd-Unternehmen logo
1 von 66
+
Your New BFFs
The WordPress Core Tables + The MySQL Database
WordCamp Pittsburgh 2017
+ Is this what you came for?
 You’re a rockstar with the front end and the WordPress admin,
but the back end is… a mystery. Ever wonder what happens
when you create a user or save a post? Where does the data
go? Let’s dive in to the MySQL database via phpMyAdmin.
We’ll explore the WordPress core tables and investigate the
fields to see how the data is stored. We’ll also touch on
optimizing your tables and creating database backups without a
plugin.
+
Hey!
 Rene Morozowich
 Freelance WordPress Developer
 In former lives I’ve been… a database developer, a
programmer and an instructor
 renemorozowich.com
 hello@renemorozowich.com
 @ReneMorozowich
+
What are we doing here?
 Follow along with your computer or just watch
 Find me on Twitter to see published slides #wcpgh
 Game plan:
 Databases are a thing
 Let’s go look at one
 WordPress uses a database
 Let’s back up and optimize the WordPress database
+
Database Basics + Lingo
+
What is a database?
 Organized collection of data
 Data is stored in tables
 Each table should be about one specific topic
 Avoid repeating data
 Tables have fields (or columns)
 Each piece of information that you want to collect about that topic
 Each field has a specific data type (what’s stored there?)
 Tables have records (or rows)
 Each record is a complete set
+
Example
CustomerID Name Address City State
1 Mary Smith 123 Main St Pittsburgh PA
2 John Doe 444 South St Pittsburgh PA
3 Lisa Jones 551 North Ave Pittsburgh PA
 Table Customer
 All fields (columns) related to the customer
 One field is a unique identifier called a primary key
 One record (row) per customer
+
Relationships
 MySQL stores relational databases
 Remember we collect data in a table about one topic
 Other topics (tables) can be related
 Think of it like a parent/child relationship
 Can call this one to many (it’s the most common)
 One parent can have many children
 We said the unique identifier in the parent table is the primary key
 The related field in the child table is the foreign key
 Same data type and let’s be cool and name them the same
+
Example
CustomerID Name Address City State
1 Mary Smith 123 Main St Pittsburgh PA
2 John Doe 444 South St Pittsburgh PA
3 Lisa Jones 551 North Ave Pittsburgh PA
OrderID CustomerI
D
Item Quantity OrderDate Paid
1234 1 Orange shirt 2 9/1/2017 Y
1235 1 Pink shoes 1 9/2/2017 Y
1236 3 Jeans 2 9/3/2017 Y
One
customer can
have many
orders
+
No no no no no no no!
Cust
omer
ID
Name Address City State OrderID Item Qua
ntity
OrderDate Paid
1 Mary
Smith
123 Main St Pittsburgh PA 1234 Orange
shirt
2 9/1/2017 Y
1 Mary
Smith
123 Main St Pittsburgh PA 1235 Pink
shoes
1 9/2/2017 Y
2 John Doe 444 South St Pittsburgh PA
3 Lisa
Jones
551 North Ave Pittsburgh PA 1236 Jeans 2 9/3/2017 Y
+
I know I just said…
 Each table should be about one specific topic
 But… there are other types of tables (the meta tables) in
WordPress
 These tables contain:
 An ID unique to the table
 An ID that corresponds back to the table they’re related to
 A key
 A value
 And they can hold almost anything
 There are drawbacks, however this allows for flexibility!!
+
MySQL + phpMyAdmin
+
About MySQL
 WordPress supports MySQL 5.0.15 or higher and any version
of MariaDB
 “The world’s most popular open source database”
 From Oracle
 Relational Database Management System (RDBMS)
 Uses Structured Query Language (SQL)
+
Getting to phpMyAdmin
 Every place is different!
 I’ll give you four examples and none are the same
 Look around your hosting environment
+
Working locally, using MAMP
 Start MAMP
 Once the servers start
 http://localhost:8888/MAMP/
opens
 See link for phpMyAdmin under
MySQL
+
Hosting, Siteground
 Log in and go to the cPanel
 In the section “Databases” choose phpMyAdmin
+
Hosting, Pair
 Log in, go to Databases, choose Manage Your Databases
 Choose the desired database, then click phpMyAdmin
 You will then have to log in with the database
username/password
+
Hosting, 1&1
 Setup as Managed by 1&1, you will not be able to see or
access your database
 You must switch to Standard mode
 Your installation is moved from their system database to your
own database
 Access under My Products, MySQL database, phpMyAdmin
+
Walking around the screen
Databases
here on the
left
+
And around
Select
database on
left
See tables
on right
+
And around…
For each
table:
Browse,
Structure,
Rows
Size and
Overhead,
too (not
pictured)
+
What are we looking at?
 The WordPress core tables!!
 There are 12 of them currently
 A bit of a mystery with wp_termmeta
 Last updated with version 4.4 (we’re on 4.8.1)
 https://codex.wordpress.org/Database_Description
 Let’s discuss what they are, how they’re related and the fields
in each table
+
But first… a note about prefixes
 The default naming for WordPress tables is wp_table_name
 There is debate on whether using a different prefix makes your
database more secure
 Some hosting companies also require you to use a prefix other
than wp_
+
WordPress Core Tables
+
Posts!
 wp_posts
 The most important!!
 More than just posts
 Also stores pages, menu items, media attachments and custom types
 wp_postmeta
 Holds extra information about individual items above
 The first of our key/value pair tables
 1 to many
 For every one post (primary key ID), there can be many meta records
(foreign key post_id)
+
Fields in wp_posts
 ID – unique number assigned to each post
 post_author – the user ID who created it (wp_users)
 post_date – time and date of creation
 post_date_gmt – GMT time and date of creation (no dependency
on a site’s timezone in the future, so brilliant)
 post_content – holds all the content for the post, including HTML,
shortcodes and other content
 post_title – title of the post
+
Fields in wp_posts
 post_excerpt – custom intro or short version of the content
 post_status – status of the post such as draft, pending,
private, publish
 comment_status – if comments are allowed
 ping_status – if the post allows ping and trackbacks
 post_password – optional password used to view the post
 post_name – URL friendly slug of the post title
+
Wait, what’s a ping?
 In the early days, blog A could notify blog B automatically when
blog A linked to blog B’s content
 The pingback would appear in blog B’s comment moderation
queue with a link to blog A’s website
 Kinda cool, but now often just used by spammers
 Turn it off under Settings, Discussion
+
Back to it. More fields in wp_posts
 to_ping – a list of URLs WP should send pingbacks to when
updated
 pinged – a list of URLs WP has sent pingbacks to when updated
 post_modified – time and date of last modification
 post_modified_gmt – GMT time and date of last modification
 post_content_filtered – used by plugins to cache a version of
post_content
 post_parent – used to create a relationship between this post and
another when this post is a revision, attachment or another type
+
Oh so many fields in wp_posts
 guid – global unique identifier, the permanent URL to the post, not
the permalink version
 menu_order – holds the display number for pages and other non-
post types
 post_type – the content type identifier (posts, revisions, pages,
menu items, media attachments and custom post types)
 post_mime_type – only used for attachments, the MIME type of
the uploaded file
 comment_count – total number of comments, pingbacks and
trackbacks
+
Fields in wp_postmeta
 meta_id – unique number assigned to each row of the table
 post_id – ID of the related post (wp_posts)
 meta_key – an identifying key for the piece of data
 meta_value – the actual piece of data
+
Terms and taxonomies
 Four term tables, but before we get to them…
 Terms
 Any descriptive words
 Taxonomies
 Category
 Tag
 Other custom ones
 Cars could be a taxonomy with terms like Toyota, Honda and Audi
 Fruits a taxonomy with terms like strawberries, apples and grapes
+
Term tables
 wp_terms
 Holds our generic terms (descriptive adjectives)
 wp_termmeta
 Holds additional data about terms
 1 to many
 For every one term (primary key term_id), there can be many meta
records (foreign key term_id)
+
Fields in wp_terms
 term_id – unique number assigned to each term
 name – the name of the term
 slug – the URL friendly slug of the name
 term_group – ability for themes or plugins to group terms
together to use aliases; not populated by WordPress core itself
+
Fields in wp_termmeta
 meta_id – unique number assigned to each row of the table
 term_id – ID of the related term (wp_terms)
 meta_key – an identifying key for the piece of data
 meta_value – the actual piece of data
+
Now with the taxonomy
 Mark each term with an appropriate taxonomy
 What’s a taxonomy again?
 Remember categories and tags
 Creating a term/taxonomy pair
+
Fields in wp_term_taxonomy
 term_taxonomy_id – unique number assigned to each row of the
table
 term_id – the ID of the related term (wp_terms)
 taxonomy – the slug of the taxonomy (category, post_tag, etc.)
 description – description of the term in this taxonomy
 parent – ID of a parent term; used for hierarchical taxonomies like
categories
 count – number of post objects assigned the term for this
taxonomy
+
Finally with the relationship
 This is a junction table!
 Many to many
 Each post can have many term/taxonomy pair records
 Each term/taxonomy pair can be used by many posts
+
Fields in wp_term_relationships
 object_id – the ID of the post object (wp_posts)
 term_taxonomy_id – the ID of the term / taxonomy pair
(wp_term_taxonomy)
 term_order – allow ordering of terms for an object, not fully
used
+
Some additional reading
 https://codex.wordpress.org/Taxonomies
 https://codex.wordpress.org/WordPress_Taxonomy
 https://en.wikipedia.org/wiki/Associative_entity
+
Comments
 wp_comments
 Each comment of a post
 wp_commentmeta
 Any additional information needed about comments; Akismet anti-
spam plugin uses this for example
 1 to many
 For every one comment (primary key comment_ID), there can be
many meta records (foreign key comment_id)
+
Fields in wp_comments
 comment_ID – unique number assigned to each comment
 comment_post_ID – ID of the post this comment relates to (wp_posts)
 comment_author – Name of the comment author
 comment_author_email – Email of the comment author
 comment_author_url – URL for the comment author
 comment_author_IP – IP Address of the comment author
 comment_date – Time and date the comment was posted
 comment_date_gmt – GMT time and date the comment was posted
+
Fields in wp_comments
 comment_content – the actual comment text
 comment_karma – unused by WordPress core; can be used by plugins to help
manage comments
 comment_approved – if the comment has been approved
 comment_agent – where the comment was posted from (browser, operating
system, etc.)
 comment_type – type of comment (comment, pingback or trackback)
 comment_parent – refers to another comment when this comment is a reply
 user_id – ID of the comment author if registered user on the site (wp_users)
+
Fields in wp_commentmeta
 meta_id – unique number assigned to each row of the table
 comment_id – the ID of the related comment (wp_comments)
 meta_key – an identifying key for the piece of data
 meta_value – the actual piece of data
+
Users
 wp_users
 Each WordPress user
 wp_usermeta
 Any additional information needed about users
 For example, first_name and last_name
 1 to many
 For every one user (primary key ID), there can be many meta
records (foreign key user_id)
+
Fields in wp_users
 ID – unique number assigned to each user
 user_login – unique username
 user_pass – hash of the user’s password
 user_nicename – user display name
 user_email – email address of the user
+
Fields in wp_users
 user_url – user’s URL
 user_registered – time and date the user registered
 user_activation_key – used for resetting passwords
 user_status – was used in Multisite pre WordPress 3.0 to
indicate a spam user
 display_name – desired name to be used publicly in the site
(user_login, user_nicename or first_name/last_name from
wp_usermeta)
+
Fields in wp_usermeta
 umeta_id – unique number assigned to each row of the table
 user_id – ID of the related user (wp_users)
 meta_key – an identifying key for the piece of data
 meta_value – the actual piece of data
+
Other
 wp_options
 Table that stores site configuration settings
 Data about themes, active plugins, widgets, temporary cached data
 Where other plugins and themes store settings
 wp_links
 Many sites used to have a blogroll (list of links to other sites)
 This table held those links!
 Removed from the admin UI
 But table remains for backwards compatibility
+
Fields in wp_options
 option_id – unique number assigned to each row of the table
 option_name – an identifying key for the piece of data
 option_value – the actual piece of data (often serialized)
 autoload – controls if the option is automatically loaded by the
function wp_load_alloptions() (puts options into object cache on
each page load)
+
Browse wp_options
Each record
in our
options table
+
Serialized Data
 Some rows store serialized data, like the active_plugins row
a:3:{i:0;s:31:"query-monitor/query-
monitor.php";i:1;s:57:"accesspress-instagram-
feed/accesspress-instagram-
feed.php";i:2;s:19:"akismet/akismet.php”;}
$array = array( '0' => 'query-monitor/query-
monitor.php' '1' => 'accesspress-instagram-
feed/accesspress-instagram-feed.php' '2' =>
'akismet/akismet.php’ );
 Read more at https://wpengine.com/support/wordpress-serialized-data/
+
Look! There it is!
+
Backup + Optimize
+
A note on backups
 Before making a change, back up your database!
 Also backup regularly
 Do it. No seriously. Do it.
+
Creating a database backup
 Choose the database, click Export and choose Custom
+
Options
 Save output to a file
+
More options
 Check Add DROP TABLE / VIEW / PROCEDURE / FUNCTION
/ EVENT / TRIGGER statement
 If the tables (etc.) are already there, they will be dropped and
recreated
+
Done!
 Click Go
 This downloads a .sql file for you
 Feel free to check it out in your text editor
+
What does optimizing mean?
 Your database will grow!
 Anytime you add/change/remove data
 A large database can affect performance
 It takes awhile for your site to fetch the data from the database
 When there’s so much to look through
 When data isn’t stored efficiently
+
It’s like…
 Cleaning out your closet
 You put things in there day after day
 It gets cluttered
 Harder and harder to find things
 Space isn’t used efficiently over time
 Defragmenting your hard drive
 And maybe a little like that 3,000 mile oil change
+
What does it actually do?
 “Reorganizes the physical storage or table data and associated
index data, to reduce storage space and improve I/O efficiency
when accessing the table”
 Got that?
 Plain English:
 Reorganizes it
 Frees up space
 Now data can get in and out more quickly (I/O)
+
How to optimize tables
 In phpMyAdmin, choose the
database on the left
 On the right at the bottom of
the table list, check “Check all”
 In the drop down “With
selected:” choose Optimize
table
+
Also…
 You may also want to purge old post revisions!
 You can do this with the database, however I don’t recommend
it
 Running insert/update/delete SQL statements can be scary!
 Try a plugin like WP-Optimize or Better Delete Revision
 You can also limit the number of post revisions you keep
 Add/modify in your wp-config.php file:
define('WP_POST_REVISIONS', 5);
+
Questions?
Thanks for attending!
+
Credits
 Field descriptions from the tables were used from
https://deliciousbrains.com/tour-wordpress-database/

Weitere ähnliche Inhalte

Ähnlich wie Your New BFFs: The WordPress Core Tables + The MySQL Database

Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologiesTOPS Technologies
 
WordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute WorkshopWordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute WorkshopBrendan Sera-Shriar
 
A Tour Through The WordPress Database
A Tour Through The WordPress DatabaseA Tour Through The WordPress Database
A Tour Through The WordPress DatabaseJulie Kuehl
 
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009Daryl Koopersmith
 
Intro to template hierarchy WCTO
Intro to template hierarchy  WCTOIntro to template hierarchy  WCTO
Intro to template hierarchy WCTOAl Davis
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and HarmonySteve Smith
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012Yaqi Zhao
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteBrendan Sera-Shriar
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme developmentThad Allender
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itOtto Kekäläinen
 
WordPress as a CMS v2
WordPress as a CMS v2WordPress as a CMS v2
WordPress as a CMS v2mwalters8
 
WordPress Template hierarchy
WordPress Template hierarchyWordPress Template hierarchy
WordPress Template hierarchyJason Yingling
 
Getting Started With WordPress Development
Getting Started With WordPress DevelopmentGetting Started With WordPress Development
Getting Started With WordPress DevelopmentAndy Brudtkuhl
 
Learning Wordpress - the internal guide
Learning Wordpress - the internal guideLearning Wordpress - the internal guide
Learning Wordpress - the internal guidetom altman
 

Ähnlich wie Your New BFFs: The WordPress Core Tables + The MySQL Database (20)

Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologies
 
WordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute WorkshopWordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute Workshop
 
A Tour Through The WordPress Database
A Tour Through The WordPress DatabaseA Tour Through The WordPress Database
A Tour Through The WordPress Database
 
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
 
Intro to template hierarchy WCTO
Intro to template hierarchy  WCTOIntro to template hierarchy  WCTO
Intro to template hierarchy WCTO
 
Mongo and Harmony
Mongo and HarmonyMongo and Harmony
Mongo and Harmony
 
Wordpress instruction for 675
Wordpress instruction for 675Wordpress instruction for 675
Wordpress instruction for 675
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
WordPress Theming 101
WordPress Theming 101WordPress Theming 101
WordPress Theming 101
 
Search in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize itSearch in WordPress - how it works and howto customize it
Search in WordPress - how it works and howto customize it
 
WordPress as a CMS v2
WordPress as a CMS v2WordPress as a CMS v2
WordPress as a CMS v2
 
WordPress Template hierarchy
WordPress Template hierarchyWordPress Template hierarchy
WordPress Template hierarchy
 
Getting Started With WordPress Development
Getting Started With WordPress DevelopmentGetting Started With WordPress Development
Getting Started With WordPress Development
 
Learning Wordpress - the internal guide
Learning Wordpress - the internal guideLearning Wordpress - the internal guide
Learning Wordpress - the internal guide
 
CMS content
CMS contentCMS content
CMS content
 
upload_test
upload_testupload_test
upload_test
 
Advanced Custom Fields Plugin
Advanced Custom Fields PluginAdvanced Custom Fields Plugin
Advanced Custom Fields Plugin
 

Kürzlich hochgeladen

Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Onlineanilsa9823
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxolyaivanovalion
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfadriantubila
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 

Kürzlich hochgeladen (20)

Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Chinhat Lucknow best sexual service Online
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
ALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptxALSO dropshipping via API with DroFx.pptx
ALSO dropshipping via API with DroFx.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 

Your New BFFs: The WordPress Core Tables + The MySQL Database

  • 1. + Your New BFFs The WordPress Core Tables + The MySQL Database WordCamp Pittsburgh 2017
  • 2. + Is this what you came for?  You’re a rockstar with the front end and the WordPress admin, but the back end is… a mystery. Ever wonder what happens when you create a user or save a post? Where does the data go? Let’s dive in to the MySQL database via phpMyAdmin. We’ll explore the WordPress core tables and investigate the fields to see how the data is stored. We’ll also touch on optimizing your tables and creating database backups without a plugin.
  • 3. + Hey!  Rene Morozowich  Freelance WordPress Developer  In former lives I’ve been… a database developer, a programmer and an instructor  renemorozowich.com  hello@renemorozowich.com  @ReneMorozowich
  • 4. + What are we doing here?  Follow along with your computer or just watch  Find me on Twitter to see published slides #wcpgh  Game plan:  Databases are a thing  Let’s go look at one  WordPress uses a database  Let’s back up and optimize the WordPress database
  • 6. + What is a database?  Organized collection of data  Data is stored in tables  Each table should be about one specific topic  Avoid repeating data  Tables have fields (or columns)  Each piece of information that you want to collect about that topic  Each field has a specific data type (what’s stored there?)  Tables have records (or rows)  Each record is a complete set
  • 7. + Example CustomerID Name Address City State 1 Mary Smith 123 Main St Pittsburgh PA 2 John Doe 444 South St Pittsburgh PA 3 Lisa Jones 551 North Ave Pittsburgh PA  Table Customer  All fields (columns) related to the customer  One field is a unique identifier called a primary key  One record (row) per customer
  • 8. + Relationships  MySQL stores relational databases  Remember we collect data in a table about one topic  Other topics (tables) can be related  Think of it like a parent/child relationship  Can call this one to many (it’s the most common)  One parent can have many children  We said the unique identifier in the parent table is the primary key  The related field in the child table is the foreign key  Same data type and let’s be cool and name them the same
  • 9. + Example CustomerID Name Address City State 1 Mary Smith 123 Main St Pittsburgh PA 2 John Doe 444 South St Pittsburgh PA 3 Lisa Jones 551 North Ave Pittsburgh PA OrderID CustomerI D Item Quantity OrderDate Paid 1234 1 Orange shirt 2 9/1/2017 Y 1235 1 Pink shoes 1 9/2/2017 Y 1236 3 Jeans 2 9/3/2017 Y One customer can have many orders
  • 10. + No no no no no no no! Cust omer ID Name Address City State OrderID Item Qua ntity OrderDate Paid 1 Mary Smith 123 Main St Pittsburgh PA 1234 Orange shirt 2 9/1/2017 Y 1 Mary Smith 123 Main St Pittsburgh PA 1235 Pink shoes 1 9/2/2017 Y 2 John Doe 444 South St Pittsburgh PA 3 Lisa Jones 551 North Ave Pittsburgh PA 1236 Jeans 2 9/3/2017 Y
  • 11. + I know I just said…  Each table should be about one specific topic  But… there are other types of tables (the meta tables) in WordPress  These tables contain:  An ID unique to the table  An ID that corresponds back to the table they’re related to  A key  A value  And they can hold almost anything  There are drawbacks, however this allows for flexibility!!
  • 13. + About MySQL  WordPress supports MySQL 5.0.15 or higher and any version of MariaDB  “The world’s most popular open source database”  From Oracle  Relational Database Management System (RDBMS)  Uses Structured Query Language (SQL)
  • 14. + Getting to phpMyAdmin  Every place is different!  I’ll give you four examples and none are the same  Look around your hosting environment
  • 15. + Working locally, using MAMP  Start MAMP  Once the servers start  http://localhost:8888/MAMP/ opens  See link for phpMyAdmin under MySQL
  • 16. + Hosting, Siteground  Log in and go to the cPanel  In the section “Databases” choose phpMyAdmin
  • 17. + Hosting, Pair  Log in, go to Databases, choose Manage Your Databases  Choose the desired database, then click phpMyAdmin  You will then have to log in with the database username/password
  • 18. + Hosting, 1&1  Setup as Managed by 1&1, you will not be able to see or access your database  You must switch to Standard mode  Your installation is moved from their system database to your own database  Access under My Products, MySQL database, phpMyAdmin
  • 19. + Walking around the screen Databases here on the left
  • 22. + What are we looking at?  The WordPress core tables!!  There are 12 of them currently  A bit of a mystery with wp_termmeta  Last updated with version 4.4 (we’re on 4.8.1)  https://codex.wordpress.org/Database_Description  Let’s discuss what they are, how they’re related and the fields in each table
  • 23. + But first… a note about prefixes  The default naming for WordPress tables is wp_table_name  There is debate on whether using a different prefix makes your database more secure  Some hosting companies also require you to use a prefix other than wp_
  • 25. + Posts!  wp_posts  The most important!!  More than just posts  Also stores pages, menu items, media attachments and custom types  wp_postmeta  Holds extra information about individual items above  The first of our key/value pair tables  1 to many  For every one post (primary key ID), there can be many meta records (foreign key post_id)
  • 26. + Fields in wp_posts  ID – unique number assigned to each post  post_author – the user ID who created it (wp_users)  post_date – time and date of creation  post_date_gmt – GMT time and date of creation (no dependency on a site’s timezone in the future, so brilliant)  post_content – holds all the content for the post, including HTML, shortcodes and other content  post_title – title of the post
  • 27. + Fields in wp_posts  post_excerpt – custom intro or short version of the content  post_status – status of the post such as draft, pending, private, publish  comment_status – if comments are allowed  ping_status – if the post allows ping and trackbacks  post_password – optional password used to view the post  post_name – URL friendly slug of the post title
  • 28. + Wait, what’s a ping?  In the early days, blog A could notify blog B automatically when blog A linked to blog B’s content  The pingback would appear in blog B’s comment moderation queue with a link to blog A’s website  Kinda cool, but now often just used by spammers  Turn it off under Settings, Discussion
  • 29. + Back to it. More fields in wp_posts  to_ping – a list of URLs WP should send pingbacks to when updated  pinged – a list of URLs WP has sent pingbacks to when updated  post_modified – time and date of last modification  post_modified_gmt – GMT time and date of last modification  post_content_filtered – used by plugins to cache a version of post_content  post_parent – used to create a relationship between this post and another when this post is a revision, attachment or another type
  • 30. + Oh so many fields in wp_posts  guid – global unique identifier, the permanent URL to the post, not the permalink version  menu_order – holds the display number for pages and other non- post types  post_type – the content type identifier (posts, revisions, pages, menu items, media attachments and custom post types)  post_mime_type – only used for attachments, the MIME type of the uploaded file  comment_count – total number of comments, pingbacks and trackbacks
  • 31. + Fields in wp_postmeta  meta_id – unique number assigned to each row of the table  post_id – ID of the related post (wp_posts)  meta_key – an identifying key for the piece of data  meta_value – the actual piece of data
  • 32. + Terms and taxonomies  Four term tables, but before we get to them…  Terms  Any descriptive words  Taxonomies  Category  Tag  Other custom ones  Cars could be a taxonomy with terms like Toyota, Honda and Audi  Fruits a taxonomy with terms like strawberries, apples and grapes
  • 33. + Term tables  wp_terms  Holds our generic terms (descriptive adjectives)  wp_termmeta  Holds additional data about terms  1 to many  For every one term (primary key term_id), there can be many meta records (foreign key term_id)
  • 34. + Fields in wp_terms  term_id – unique number assigned to each term  name – the name of the term  slug – the URL friendly slug of the name  term_group – ability for themes or plugins to group terms together to use aliases; not populated by WordPress core itself
  • 35. + Fields in wp_termmeta  meta_id – unique number assigned to each row of the table  term_id – ID of the related term (wp_terms)  meta_key – an identifying key for the piece of data  meta_value – the actual piece of data
  • 36. + Now with the taxonomy  Mark each term with an appropriate taxonomy  What’s a taxonomy again?  Remember categories and tags  Creating a term/taxonomy pair
  • 37. + Fields in wp_term_taxonomy  term_taxonomy_id – unique number assigned to each row of the table  term_id – the ID of the related term (wp_terms)  taxonomy – the slug of the taxonomy (category, post_tag, etc.)  description – description of the term in this taxonomy  parent – ID of a parent term; used for hierarchical taxonomies like categories  count – number of post objects assigned the term for this taxonomy
  • 38. + Finally with the relationship  This is a junction table!  Many to many  Each post can have many term/taxonomy pair records  Each term/taxonomy pair can be used by many posts
  • 39. + Fields in wp_term_relationships  object_id – the ID of the post object (wp_posts)  term_taxonomy_id – the ID of the term / taxonomy pair (wp_term_taxonomy)  term_order – allow ordering of terms for an object, not fully used
  • 40. + Some additional reading  https://codex.wordpress.org/Taxonomies  https://codex.wordpress.org/WordPress_Taxonomy  https://en.wikipedia.org/wiki/Associative_entity
  • 41. + Comments  wp_comments  Each comment of a post  wp_commentmeta  Any additional information needed about comments; Akismet anti- spam plugin uses this for example  1 to many  For every one comment (primary key comment_ID), there can be many meta records (foreign key comment_id)
  • 42. + Fields in wp_comments  comment_ID – unique number assigned to each comment  comment_post_ID – ID of the post this comment relates to (wp_posts)  comment_author – Name of the comment author  comment_author_email – Email of the comment author  comment_author_url – URL for the comment author  comment_author_IP – IP Address of the comment author  comment_date – Time and date the comment was posted  comment_date_gmt – GMT time and date the comment was posted
  • 43. + Fields in wp_comments  comment_content – the actual comment text  comment_karma – unused by WordPress core; can be used by plugins to help manage comments  comment_approved – if the comment has been approved  comment_agent – where the comment was posted from (browser, operating system, etc.)  comment_type – type of comment (comment, pingback or trackback)  comment_parent – refers to another comment when this comment is a reply  user_id – ID of the comment author if registered user on the site (wp_users)
  • 44. + Fields in wp_commentmeta  meta_id – unique number assigned to each row of the table  comment_id – the ID of the related comment (wp_comments)  meta_key – an identifying key for the piece of data  meta_value – the actual piece of data
  • 45. + Users  wp_users  Each WordPress user  wp_usermeta  Any additional information needed about users  For example, first_name and last_name  1 to many  For every one user (primary key ID), there can be many meta records (foreign key user_id)
  • 46. + Fields in wp_users  ID – unique number assigned to each user  user_login – unique username  user_pass – hash of the user’s password  user_nicename – user display name  user_email – email address of the user
  • 47. + Fields in wp_users  user_url – user’s URL  user_registered – time and date the user registered  user_activation_key – used for resetting passwords  user_status – was used in Multisite pre WordPress 3.0 to indicate a spam user  display_name – desired name to be used publicly in the site (user_login, user_nicename or first_name/last_name from wp_usermeta)
  • 48. + Fields in wp_usermeta  umeta_id – unique number assigned to each row of the table  user_id – ID of the related user (wp_users)  meta_key – an identifying key for the piece of data  meta_value – the actual piece of data
  • 49. + Other  wp_options  Table that stores site configuration settings  Data about themes, active plugins, widgets, temporary cached data  Where other plugins and themes store settings  wp_links  Many sites used to have a blogroll (list of links to other sites)  This table held those links!  Removed from the admin UI  But table remains for backwards compatibility
  • 50. + Fields in wp_options  option_id – unique number assigned to each row of the table  option_name – an identifying key for the piece of data  option_value – the actual piece of data (often serialized)  autoload – controls if the option is automatically loaded by the function wp_load_alloptions() (puts options into object cache on each page load)
  • 52. + Serialized Data  Some rows store serialized data, like the active_plugins row a:3:{i:0;s:31:"query-monitor/query- monitor.php";i:1;s:57:"accesspress-instagram- feed/accesspress-instagram- feed.php";i:2;s:19:"akismet/akismet.php”;} $array = array( '0' => 'query-monitor/query- monitor.php' '1' => 'accesspress-instagram- feed/accesspress-instagram-feed.php' '2' => 'akismet/akismet.php’ );  Read more at https://wpengine.com/support/wordpress-serialized-data/
  • 55. + A note on backups  Before making a change, back up your database!  Also backup regularly  Do it. No seriously. Do it.
  • 56. + Creating a database backup  Choose the database, click Export and choose Custom
  • 58. + More options  Check Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement  If the tables (etc.) are already there, they will be dropped and recreated
  • 59. + Done!  Click Go  This downloads a .sql file for you  Feel free to check it out in your text editor
  • 60. + What does optimizing mean?  Your database will grow!  Anytime you add/change/remove data  A large database can affect performance  It takes awhile for your site to fetch the data from the database  When there’s so much to look through  When data isn’t stored efficiently
  • 61. + It’s like…  Cleaning out your closet  You put things in there day after day  It gets cluttered  Harder and harder to find things  Space isn’t used efficiently over time  Defragmenting your hard drive  And maybe a little like that 3,000 mile oil change
  • 62. + What does it actually do?  “Reorganizes the physical storage or table data and associated index data, to reduce storage space and improve I/O efficiency when accessing the table”  Got that?  Plain English:  Reorganizes it  Frees up space  Now data can get in and out more quickly (I/O)
  • 63. + How to optimize tables  In phpMyAdmin, choose the database on the left  On the right at the bottom of the table list, check “Check all”  In the drop down “With selected:” choose Optimize table
  • 64. + Also…  You may also want to purge old post revisions!  You can do this with the database, however I don’t recommend it  Running insert/update/delete SQL statements can be scary!  Try a plugin like WP-Optimize or Better Delete Revision  You can also limit the number of post revisions you keep  Add/modify in your wp-config.php file: define('WP_POST_REVISIONS', 5);
  • 66. + Credits  Field descriptions from the tables were used from https://deliciousbrains.com/tour-wordpress-database/

Hinweis der Redaktion

  1. What data types are there?
  2. Notice all fields in the orders table relates to the order How many orders did each customer place? Who placed the orders?
  3. Why is this bad? Duplicate data – Mary Smith Increase in chances that something won’t be updated