Affichage des articles dont le libellé est Database. Afficher tous les articles
Affichage des articles dont le libellé est Database. Afficher tous les articles

samedi 12 novembre 2016

User Management Within MySQL Database With phpMyAdmin



alt="User Management Within MySQL Database With phpMyAdmin" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2015/04/default-image-500x308_c.jpg" />

There are situations when you can’t simply open your CMS or forum installation and manage users from inside the platform. Suppose you’ve been hacked and can’t access your admin account – what will you do?

Coming to your rescue is a web-based MySQL front-end — phpMyAdmin —  that helps you manage your site user accounts by performing actions directly on the database. The tool is integrated with all the major domain control panels (cPanel, Plesk, VistaPanel, etc.) and, when not present, it can be installed on your server via Fantastico or Softaculous (automated script installers that come with a domain control panel). Manual installation will not be considered for this short guide.

What Is phpMyAdmin?

href="http://www.phpmyadmin.net/" target="_blank">phpMyAdmin is a web-based, open source PHP tool for MySQL database management. Tobias Ratschiller, its inventor, started to work on phpMyAdmin on 1998 as an alternative to MySQL-Webadmin, but he dropped the project on 2000 because he had no time to maintain it. The development was taken over by three programmers on 2001, who founded The phpMyAdmin Project. Its success among webmasters is due to a user-friendly, easy-to-use web interface and the possibility to access the tool from a domain control panel (cPanel, Plesk, VistaPanel).

What Approach Will This Guide Take?

You can use two approaches to database management within phpMyAdmin:

  • management via phpMyAdmin interface
  • management via SQL query execution

This guide will show you how to use each of the two approaches to perform SQL operations on your user base.

Example Software In This Guide

Among the most popular CMS and forum scripts, the choices for this guide fell for WordPress and XMB Forum, although the tutorial can easily be applied to any user-based site software in general. The guide will show you how to use both of the two above mentioned approaches for each script’s database user table.

phpMyAdmin User Management for WordPress

Interface Method

Login into your cPanel account (or any other web hosting control panel with your domain). Look for phpMyAdmin under the group ‘Databases’ and click on the phpMyAdmin icon:

src="http://www.webhostingsecretrevealed.com/images/2012/0416-1.jpg" class="border" alt="Databases in cPanel" width="600" height="149" />

The phpMyAdmin web interface will open in a new window. Once you’re in, select the database you need to work on from the left sidebar. In our example, the database is wptest_wp234. Click it.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-2.jpg" class="border" alt="phpMyAdmin" width="600" height="256" />

When you open your database, you will see a list of all its tables on the left sidebar, while the main page shows you a list of those same tables with browsing/editing tools (per row). To access your users list, click on the ‘wp_users’ table and look up the list of users.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-3.jpg" class="border" alt="WP Users" width="600" height="181" />

You may need to change your credentials, email, website URL, etc. Open the row associated with your user account by clicking “Edit” (there’s a pencil icon next to the link) to start editing your information. The image below shows the user info fields you can edit.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-4.jpg" class="border" alt="User Info Edit" width="600" height="306" />

To change your password, you need to select MD5 from the drop-down menu. Write a strong password (you can use a href="http://www.thebitmill.com/tools/password.html" target="_blank">random password generator for better results). Once you’re done, save your changes.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-5.jpg" class="border" alt="MD5 Password Edit" />

The MD5 is acronym for Message-Digest (algorithm) v. 5, a cryptographic hash function that returns a 32-digits value. The ‘user_pass’ field will automatically convert your new password into a MD5 32-digits string.

id="right">src="http://www.webhostingsecretrevealed.com/images/2012/0416-6.jpg" alt="Edit Link for User Rows" />

In case you need to get rid of all spam accounts, just go back to the ‘wp_users’ table, select the user rows of choice and hit the “Delete” button at the bottom of the page. If you need to remove a single user, intead, simply hit the “Delete” link on the user row (see image here on the right).

SQL Query Method

phpMyAdmin allows database managers to execute SQL statements directly on the web interface. When you open your database in phpMyAdmin, you’ll see a series of tabs on the main page — Browse, Structure, SQL, Search, Insert, Export, Import, Operations: click the SQL tab to access an SQL web shell in which to write and run your statements. Refer to the 4th screenshot in this guide for the exact tab location.

Following are 3 code snippets you can use to edit user accounts by SQL operations.

NOTE: By ‘youraccountname’ I mean your hosting account username. This is the most common form of database identification on shared hosting environments, where each database is assigned to a specific user. Hence the underscore(“_”) between your hosting account username and your database name. There are other forms of database identification that only use a database name. The convention you will use is the one shown in your phpMyAdmin installation.

1. Change user password (MD5):

UPDATE `youraccountname_databasename`.`wp_users`
SET `user_pass` = MD5( ‘testuserpasswhere’ )
WHERE `ID` =2;

What does this code do?

  • UPDATE `youraccountname_databasename`.`wp_users`edits and updates the ‘wp_users’ table inside the database ‘youraccountname_databasename’.
  • SET `user_pass` = MD5( ‘testuserpasswhere’ )sets the value of the attribute ‘user_pass’ to the MD5 hash string of ‘testuserpasswhere’.
  • WHERE `ID` =2;tells you that the user ID you’re applying modifications to is the #2. Obviously this is an example ID here; it can be any user ID of choice.

2. Edit user info:

UPDATE `youraccountname_databasename`.`wp_users`
SET `user_login` = ‘newusername’,
`user_nicename` = ‘newusername’,
`user_email` = ‘newusername@domain.com’
WHERE `ID` = 1;

What does this code do?

  • As for the first snippet, the UPDATEline specifies which table will be modified, and in which database.
  • The SETfunction here operates on 3 different attributes: it sets ‘user_login’ and ‘user_nicename’ to a new value ‘newusername’, and ‘user_email’ to ‘newusername@domain.com’. Mind that ‘user_login’ and ‘user_nicename’ are two different attributes with the same value: the former is the username used to login, the latter is the name that will be shown on your website pages. Example: ‘greatboy84’ is the login name, ‘Frank Span’ is the name shown on page.
  • WHERE `ID` = 1;tells you that the user ID you modified is number #1.

3. Delete spammer account:

DELETE FROM `youraccountname_databasename`.`wp_users`
WHERE `ID` = 2

What does this code do?

  • The first line tells you that you’re going to delete something from the ‘wp_users’ table from database ‘youraccountname_databasename’.
  • WHERE `ID` = 2means the user ID you’re deleting is #2.

phpMyAdmin User Management for XMB Forum

Interface Method

The procedure is similar to WordPress user management.

Login to your domain control panel and open phpMyAdmin. Select your forum database and look for the table ‘xmb_members‘: it contains your forum’s member accounts.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-7.jpg" class="border" alt="XMB Forum Members List MySQL" />

Click ‘Edit’ on the row associated with your user account and edit your user info (see image below). Hit the ‘Go’ button to save your changes.

src="http://www.webhostingsecretrevealed.com/images/2012/0416-8.jpg" class="border" alt="XMB User Edit" />

SQL Query Method

The following 2 code snippets show you how to edit or delete an XMB user account via MySQL.

1. Edit XMB member account:


UPDATE `youraccountname_xmbdatabase`.`xmb_members`
SET `username` = ‘bigsmurf85’,
`password` = MD5( ‘xmbuser178pass’ ) ,
`email` = ‘testmail@gmx.com’,
`site` = ‘http://domain.com’,
`location` = ‘US’
WHERE `uid` =139;

As with the WordPress examples above, this SQL code updates a user’s current information to new specified values.

2. Delete XMB member account:


DELETE FROM `youraccountname_xmbdatabase`.`xmb_members`
WHERE `uid` = 178

The first line says you’re going to delete one or more user IDs (‘uid’ here) from the database ‘xmb_members’. The second specifies the user ID number, 178 in this case.

A Password Security Tip

The MD5 algorithm has first proven vulnerable on 1996, when href="cseweb.ucsd.edu/~bsy/dobbertin.ps" target="_blank">Hans Dobbertin discovered collisions in the MD5 hash function, and more href="http://www.infosec.sdu.edu.cn/uploadfile/papers/How%20to%20Break%20MD5%20and%20Other%20Hash%20Functions.pdf" target="_blank">reports were shared with the public over the years. When we say ‘collisions’ we intend situations in which different strings of characters (i.e. passwords) have the same hash value. The material is ample and can’t certainly be covered by a single paragraph in a short guide, but do not fear– MD5 can still save you from a lot of headaches as it was explained in this guide. However, the next safety step to take after you changed your password in phpMyAdmin (using the MD5 encryption) is to change it again in your WordPress user profile. In fact, WordPress will encrypt your password using a library called href="http://www.openwall.com/phpass/" target="_blank">phpass, that includes safer and therefore not easily breakable algorithms.

The ‘Lazy’ Trick!

To be lazy does not necessarily result in wrong choices. More often than ever, the tricks we develop to save time convert into website efficiency and higher traffic, so let’s not overlook this paragraph.

The ‘lazy trick’ is to take advantage of a spammer’s user account to create a fictional character’s or friend’s account. How?

The procedure is simple – all you need to do is open your users list inside your database (you can use the interface approach for this kind of easy task), click the “Edit” button for the chosen user row and edit the following fields (leave the ID as is):

  • user_login, user_pass, user_nicename, user_email
  • optional details (user_url, user_registered, etc.)

In alternative, you can use the SQL query snippet for user account editing I showed you earlier in this guide.

When will this trick turn out useful?

Oh, let’s list a few significant examples: you may need fake accounts on your forum or blog to test new plugins, hacks and mods, or perhaps you want to register accounts for your busy friends to have them ready to use. Also, you may need to use a ‘forum bot’ that publishes board rules, section rules and so on. Really, your imagination is the limit. :)

Bonus SQL Code: Create A User Account

A small extra bonus won’t hurt, will it? Following are two SQL code snippets: the first creates a new user account for your WordPress site, the second a new XMB Forum user.

INSERT INTO `youraccountname_databasename`.`wp_users` (
`user_login` ,
`user_pass` ,
`user_nicename` ,
`user_email` ,
`user_registered` ,
`user_status`
)
VALUES (
‘newusername3’,
MD5( ‘newpassword3’ ) ,
‘Mally Bally’,
‘mallybally@domain.com’,
‘2012-04-13 00:00:00’,
‘1’
)

The sample code will create a new user and will assign values (user information) to the attributes ‘user_login’, ‘user_pass’, ‘user_nicename’, ‘user_email’, ‘user_registered’ and ‘user_status’.

To create a new XMB Forum member:

INSERT INTO `youraccountname_databasename`.`xmb_members` (
`username` ,
`password` ,
`email` ,
`status`,
`location`
)
VALUES (
‘fairyland’,
MD5( ‘fairypass123’ ) ,
‘fairyland@domain.com’,
‘Member’,
‘US’
)

Have fun! :)


Page 24 – Web Hosting Secret Revealed




WordPress How-To: Install Multiple WP Blogs With One Single Database



alt="WordPress How-To: Install Multiple WP Blogs With One Single Database" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2013/01/web-server-data-500x202_c.jpg" />

As an open source content management system, WordPress often finds itself installed on href="http://www.webhostingsecretrevealed.net/hosting-review/ipage/">lower-cost, href="http://www.webhostingsecretrevealed.net/hosting-review/webhostinghub/">budget hosting plans which permit clients to have limited number MySQL or PostgreSQL database per account. This is no problem for those users who plan to only host just one or two WordPress blog, but can be a significant road block for those WordPress users who aspire to host their friends, family members, or a thriving community of independent bloggers.

Luckily, WordPress offers a number of ways to permit multiple installations of the software within just one database, saving users both a significant usability headache and the higher cost that comes from seeking a hosting plan which supports multiple MySQL databases.

The road to enabling multiple installations in a single WordPress database involves extensive editing to the software’s site-wide configuration file for many users. WordPress supports hosting multiple blogs with one installation of the software, or installing multiple instances of the software into one database. Those who choose to do this will need to be familiar with the configuration PHP file, their .htaccess file, and other server settings which are determined remotely by their current web host. Those who are comfortable knowing and modifying these settings are urged to complete this process, as it will likely be simple and take just a few minutes from start to finish.

Step 1: Locating and Changing Settings in the WP-Config.php System File

class="border" alt="Locating and Modifying WP Config" src="http://www.webhostingsecretrevealed.net/images/2012/0418-1.jpg" width="750" />

Every WordPress installation relies on “wp-config.php” to control database usernames, passwords, and locations, as well as settings relating to actual software features and user information. This file is rarely modified, except for in the first steps of a typical installation, and many WordPress developers and novice users may not be sure where to locate the file or which edits to make. For clarification, this configuration file lies in the root directory of every WordPress installation. This will typically be the “public_html” folder for a primary installation, and the base of a subfolder for each subsequent install of the WordPress software.

Once the file is located, it can be edited using an FTP client’s built in file and text editor. Doing this process directly on the server ensures that all edits are made to the remote file and saved directly, eliminating potential data loss and confusion between different versions of the configuration file. When the file is opened, there are a few settings that need to be changed when installing the WordPress software multiple times using the same database.

We will need to href="http://codex.wordpress.org/Editing_wp-config.php" target="_blank">configure our “wp-config.php” file in order to customize our WordPress installation. First and foremost, the actual database information must be entered. If this is the first (and primary) installation, the database name, username, and password can be both defined and discovered using the server’s control panel. Both the cPanel and Plesk Panel software have a specific database configuration area that displays this information to users upon request. Fill in all information accurately, as failure to connect to the database will result in a failed installation overall.

Step 2: Changing the Structure of the WordPress Database

class="border" alt="Customizing WP Database" src="http://www.webhostingsecretrevealed.net/images/2012/0418-2.jpg" width="750" />

Every WordPress download comes with a default configuration file which designates a “wp_” prefix to the entire installation. This prefix will be added on to every table which is created by the installer and is designed to separate the WordPress tables from other applications residing in the same database. Similarly, this prefix can be changed in order to separate different WordPress installations from each other. Changing the database prefix is perhaps the most central step to ensuring that WordPress installations can function alongside each other in the same database without overwriting each others’ data, granting the wrong user permissions, or publishing the wrong content.

What to look for in wp-config.php?

In the still-open “wp-config.php” configuration file for the WordPress installation in question, locate the line which determines the database prefix which will be used. It almost always looks like the following example:

$table_prefix = ‘wp_’;

As can be seen, the WordPress developers have loaded the file with the default “wp_” prefix. This can be used for the first or primary WordPress blog installed to a server, but it cannot be used for any secondary installation. Using the same database for multiple blogs will lead to data loss, erroneous content, and all kinds of user permission problems that could enable malicious activity between blogs.

Change this prefix to almost anything else, so long as it is all lowercase and contains no spaces or punctuation marks. The “_” underscore character is not a requirement, as periods or hyphens can also be used. However, be aware that the underscore character is considered the standard way of separating a prefix from a table name, and it’s the easiest to use when scanning database records for certain iterations or cells.

Step 3: Proceed with Installation

If all you wish to do is simply install multiple WordPress blogs into separate databases with entirely separate groups of users and administrators, the process is largely complete. With the correct database information placed into the file, and the proper table prefix in place of the default WordPress-generated option, everything will likely go off without a hitch. However, advanced users might be interested to know that installing multiple WordPress blogs into the same database enables a unique kind of data sharing. Because user tables are all placed into the same database, WordPress can actually be instructed to use the same set of users between multiple blogs; this can be done on a per-installation basis, as well, so only the right users are given access to multiple points of entry and content publication.

For those advanced users who wish to create a site-wide user list that can publish content across multiple blogs, this edit is relatively straightforward to make and must be done at the beginning of the installation process before the actual installation page has been loaded. It’s easy to do, and the process is presented in the next step for those who are so inclined to give it a go.

Step 4: Sharing Users and User Meta Information Among Multiple Same-Database Installations

id="right">

An important consideration to be made when installing many WordPress iterations into just one database is whether or not the users of each website will need to login to a different website within the same domain name’s purview. This can be especially true for href="http://wphacks.com/best-magazine-style-wordpress-themes/" target="_blank">“magazine-style” sites which categorize their content into subfolders and subdomains, with each content creation department having their own WordPress installation and content creation portal. Having a different user account for all users on every blog can be time-consuming and it’s largely an outdated practice.

The “wp-config.php” file can be amended to instruct a WordPress installation to place all data within its prefixed tables, but to pull user information from a differently-prefixed table. This means the primary blog’s user list could potentially because the user list of all blogs installed into subfolders across a website. Here’s how it’s done.

define(‘CUSTOM_USER_TABLE’, $table_prefix.’global_users’);
define(‘CUSTOM_USER_META_TABLE’, $table_prefix.’global_usermeta’);

These two lines must be added to the “wp-config.php” file before the WordPress software is installed. Notice that the tables utilized for user information are prefixed with “global.” This allows both the primary installation and all secondary installations to access the same, universal tables full of user information. It gives no specific WordPress installation control over the user databases, as each WordPress installation remotely accesses that information via the “global” tables.

The two lines of code above could be modified to be named otherwise, including using the standard “wp_users” and “wp_usermeta” tables for those blogs which will simply access information already determined by the site’s primary WordPress installation. Developers should modify these lines intelligently and at their own risk, and remember to do so before installation as it’s exceedingly complex to change the user tables after an install has been completed.

Installing Side-by-Side WordPress Installations is Largely an Outdated Practice

While WordPress will likely never drop support for custom MySQL table prefixes and multiple installations of the software in the same database, the company’s developers have been hard at work on creating a solution which can perform all of the above tasks on an automated, on-the-fly basis. This means being able to create multiple WordPress blogs by using the standard WordPress Dashboard interface, largely eschewing the “wp-congif.php” file edits and database trickery that is used to share user information among separate installations. WordPress provides a showcase of many blogs which use this feature in its href="http://wordpress.org/showcase/flavor/wordpress-ms/" target="_blank">MultiSite Showcase as a demonstration of just how functional, open-ended, and easy a Network is to create and maintain.

The feature is included in href="http://wordpress.org/news/2010/06/thelonious/" target="_blank">WordPress 3.0 and higher, and it’s known as “WordPress Networks.” The company had previously developed the feature as an entirely separate version of WordPress, known as “WordPress MU,” but made the decision to integrate the two during the release of its most recent software version. The feature, while fully functional and quite robust, is not enabled by default. Users will still need to work a little PHP magic within the site’s configuration file in order to be able to access these new and innovative features.

Instead of modifying the database prefix set out in the “wp-congfig.php” file, users will instead bypass that setting and define an entirely new line of code. This line of code instructs the WordPress Dashboard to enable the multisite, or WordPress Networks, configuration options and setup tools. The line to be pasted into the configuration file is this one:

define(‘WP_ALLOW_MULTISITE’, true);

It’s pretty simple, and saving the file will immediately allow the WordPress Dashboard to show the setup and configuration panel within its interface. That’s exact where the user should head next, as the Dashboard is the central feature of WordPress Networks setup.

Once in the Dashboard, click the “Administration” heading in the sidebar and then click “Tools.” Beneath this, a new option named “Network Setup” will appear, and it should be clicked. WordPress will determine whether new blogs should be installed as subfolders or subdomains, and it will ask for a defined directory where it should place blog media uploads (pictures, movies, audio files, and more). With those settings defined, it will get to work and define new database tables, cells, and users. The process may take a few moments.

After the initial configuration has been completed, the site administrator will be presented with a page that instructs them to configure their “wp-config.php” and “.htaccess” files further. These changes will initialize the media upload directory, make essential changes to the way permalinks work for multiple WordPress installations, and enable more of the special WordPress Networks features that set this type of installation apart from standard WordPress versions.

The best part about using this feature is probably the minimal impact it has on the site’s database. Rather than burdening the database with a long list of tables and cells, it installs most of the new information into an existing database structure that doesn’t need to be modified at all. The few extra tables and cells it does install are minimal and efficient, meaning site load times will not suffer as a result of the installation. That cannot be said for databases which play host to many side-by-side WordPress installations which are installed the “old-fashioned way.”

A Note of Caution: Always Be Careful with the MySQL Database

For the most part, there are very few risks associated with installing WordPress to a database in multiple instances. But, as with any change to the site’s database, always have a backup on hand and be ready to restore your data with it. Modifying the database and placing tables side-by-side has been known to occasionally cause incidental data loss which can only be recovered with a backup. Furthermore, accidents do occur and people have been known to forget the essential step of modifying the database prefix. This results in a complete loss of pages, posts, and users.

With the right precautions in place, and careful attention to detail, it is entirely possible to run multiple WordPress blogs from within the same database. Both the old method, as well as the new WordPress Networks feature, can create advanced blog setups that enable robust levels of content, shared user access, and easier usage of the site’s resources than many competing content management solutions would allow for.

Follow Up Reading

This post is part of my WordPress How-To Series. You might also want to check out other popular post on this topic: title="Most Wanted WordPress Code Snippets" href="http://www.webhostingsecretrevealed.net/blog/web-design/25-handy-code-snippets-for-wordpress-developers/">25 Handy Code Snippets For WordPress Developers as well as title="Must Learn WordPress Tricks And Hacks" href="http://www.webhostingsecretrevealed.net/blog/blogging-tips/25-most-wanted-wordpress-tips-tricks-and-hacks/">Most Wanted WordPress Hacks, Tips, And Tricks.


Page 24 – Web Hosting Secret Revealed




7 Tips To Reduce WordPress Database Size



alt="7 Tips To Reduce WordPress Database Size" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/database-500x225_c.jpg" />

Serious about speeding up your WordPress-hosted website?

Then you’ve likely shelled out money for a clutter-free design or codes that reduce the loading time of your site.

And if you’re anything like the typical webmaster, you eagerly devour the worksheets, ebooks and webinars that teach you to increase site speed.

But it turns out, you may not need to pony up some dough.

Why, you ask?

Because reducing the size of your WordPress database can significantly reduce your site’s loading time and improve its speed.

It’s no secret that search engines give a lot of href="http://www.searchenginejournal.com/faster-wordpress-need-speed/113155/" target="_blank">importance to site speed, and that your website loading time can affect your search rankings in a small percentage. This does not specifically mean a faster website will boost your ranking, but it assists crawlers to access your web pages easily and provide a better user experience to visitors.

And the larger your WordPress database is, the more time it could take to render pages for those visiting your website. So it’s essential for you to href="http://www.webhostingsecretrevealed.net/blog/wordpress-blog/wordpress-performance-optimization-data-comes-before-optimization/" target="_blank">cleanup your WordPress database and reduce its size. Over time, your database may have unused records, redundant entries and tables which you can safely remove without affecting other elements of your site. This will assist in removing the load time on your server and improve the performance of your site.

Curious about how to reduce the size of your WordPress database? What follows are seven steps to reduce WordPress database size that can be put into practice instantly:

1. Delete unwanted plugins

class="alignright wp-image-10706 size-medium" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/1-300x234.png" alt="1" width="300" height="234" srcset="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/1-300x234.png 300w, http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/1.png 396w" sizes="(max-width: 300px) 100vw, 300px" />

Did you know there are over 20,000 WordPress plugins? The ease with which you can install a plugin is a blessing and a curse at the same time. Your database will always suffer from plugin bloat, as each plugin, even when deactivated, adds more code for WordPress to load.

So do your database, and your site, a favor, and delete all those plugins you haven’t used in a while. This can be done easily through the plugin section in your WordPress dashboard.

2. Delete spam comments and unwanted codes

class="alignright wp-image-10707" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/2.png" alt="2" width="300" height="210" srcset="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/2.png 750w, http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/2-300x210.png 300w" sizes="(max-width: 300px) 100vw, 300px" />

There should be comments and posts in your spam and trash folder: this is the unnecessary clutter you need to remove. You should also delete any post revisions that were left as drafts and new posts were published instead.

You can use the href="https://wordpress.org/plugins/wp-optimize/" target="_blank">WP-optimize plugin to get the job done with a single click. At the same time, you can use Clean Options for WordPress plugin to find unused tables in your database and clean them as well.

3. Use MySQL queries

Akismet plugin increases the database size in many instances due to the table called wp_commentmeta. Install the href="https://wordpress.org/plugins/wp-dbmanager/" target="_blank">WP db manager plugin > run the following two query options – they can be executed from the WordPress dashboard (but run each of them separately):

DELETE FROM wp_commentmeta WHERE comment_id NOT IN (SELECT comment_id FROM wp_comments);
DELETE FROM wp_commentmeta WHERE meta_key LIKE ‘%akismet%’;

Your WordPress installation might be a bit different, so don’t forget to check your table name before applying the queries above. The following SQL queries are also helpful in reducing database size:

DELETE FROM wp_postmeta WHERE meta_key = "_edit_lock";
DELETE FROM wp_postmeta WHERE meta_key = "_edit_last";

4. Compress images

class="alignright wp-image-10709 size-medium" src="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/4-300x170.png" alt="4" width="300" height="170" srcset="http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/4-300x170.png 300w, http://whsr.webrevenueinc1.netdna-cdn.com/wp-content/uploads/2014/09/4.png 724w" sizes="(max-width: 300px) 100vw, 300px" />

Compressing your images can greatly reduce the amount of data residing in your database. You can use gzip compression to reduce the size of text based resources such as CSS, JavaScript and HTML.

You can also use the href="https://wordpress.org/plugins/wp-smushit/" target="_blank">WP Smush.it plugin that will compress images when you upload new ones to the media library by stripping meta data from JPEGs, converting GIFs to indexed PNGs, stripping the unused colors from indexed images, and optimizing JPEG compression. WP Smush.it will run quietly behind the scenes.

5. Turn off Autosave

WordPress saves the changes you make to posts every 2 minutes and stores them as revision. All the revisions of a single post are saved as separate entries in the database, which makes the database drastically large.

If you’re writing long posts, turning off the autosave feature is viable solution. Add the following code to your functions.php file between the closing and opening php tags:

function disableAutoSaveCompletely() {
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'disableAutoSaveCompletely' );

6. Optimize WordPress database

The database is the place where everything is stored: comments, settings, pages, posts, plugins and codes. A bloated database means every time a page is reloaded, it can take longer for the information to be found and displayed.

This is why you need to optimize your database. Using href="https://wordpress.org/plugins/wp-dbmanager/" target="_blank">WP-DB manager or href="https://wordpress.org/plugins/wp-optimize/" target="_blank">WP optimize plugin is a great way to restore, repair, optimize and backup your database.

7. Use cache plugins

Caching plugins such as href="https://wordpress.org/plugins/w3-total-cache/" target="_blank">W3 Total Cache create a static version of your pages for first time visitors. So the database is accessed to generate your page when someone visits it for the first time.

With a cache plugin, the generated page is stored on the server, so when a user visits a page for the next time, the same page is pre-generated and the database isn’t called in.

Take the following measures to optimize your WordPress database. You’ll notice instant results.


Page 12 – Web Hosting Secret Revealed