ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Optimizing MySQL For VPS / Dedicated Server

Updated on December 31, 2010

Tuning Server Parapeters

MySQL is an open source database software based on the SQL vocabulary which can be employed in combination with most server-side languages, but which is most commonly employed with PHP. MySQL has become the de facto standard for high-traffic web sites because of its high performance, stability and ease of use.

You can Tune your MySQL server parapeters to try to optimize your configuration. As a reminder, you can check the current values of server parameters with this:

show variables;

You can see the effects of your server configuration by looking at the output of this:

show status;

There's a number of performance tuning scripts that will analyze your server settings and current status and give you information on recommended changes that you should make. You shouldn't necessarily follow all of the suggestions, but it's worthwhile to take a look at anyway.


1) You need ssh access to your server. If you don't have root ssh access, you will need to contact your web host.

2) To connect to your server:

If you are on Windows, you can use PuTTY.

In the Session section:

- Enter or your ip as Host Name

- Select SSH2 as protocol

- Click Open

You can now login secure to your server.

If this is your first time using PuTTy, then read this page for more details on how to set up PuTTy.

Using a MySQL Performance Tuning Analyzer Script

MySQL Performance Tuning Primer Script is a script that analyzes your MySQL performance and, based on the statistics it gathers, gives recommendations which variables you should adjust in order to increase performance. That way, you can tune your my.cnf file to tease out the last bit of performance from your MySQL server and make it work more efficiently.

This script takes information from "SHOW STATUS LIKE" and "SHOW VARIABLES LIKE" to produce sane recommendations for tuning server variables. It is compatible with all versions of MySQL 3.23 and higher (including 5.1).

Before you continue, make sure your MySQL server has at least 48 hours uptime. It's very important for the script in order to adjust variables corectly.


While logged into your server through ssh, type:

wget to download it

then chmod u+x to set the proper permissions,

and finally ./ to run the program. The script will analyze your server and suggest the proper settings.

You should carefully read the output, especially the recommendations at the end. It shows exactly which variables you should adjust in the [mysqld] section of your my.cnf (on Debian and Ubuntu the full path is /etc/mysql/my.cnf). Whenever you change your my.cnf, make sure that you restart MySQL. You can then run MySQL Script again to see if it has further recommendations to improve the MySQL performance. This way, you can optimize MySQL step by step.

Blue color means the name of the server parameter checked. White color is common text. Green color means that value/parameter is set OK while red one means there are some deficiencies found and recommendations for better performance are offered.

How to edit my.cnf

There are two editors that are pre-installed on your server that you can use. They are called "nano" and "vi". Of the two, nano will be easier to use, because its key combinations are provided right on the screen as you work. To edit a file, first make a back-up:

cp /etc/my.cnf /etc/my.cnf.old

You can edit your mysql configuration (/etc/my.cnf) by typing:

vi /etc/my.cnf or nano /etc/my.cnf.

When finished, ctrl X back out and type "y" to save and overwrite the file.

Then restart mysql

/etc/init.d/mysql restart (or /etc/init.d/mysqld restart)

The settings below should work well for a server with 512MB Guaranteed RAM:









This changes can be made on the MySQL DB but any mysqld restarts would revert the changes back again.



SET GLOBAL query_cache_type=1;

SHOW VARIABLES LIKE 'query_cache_type';

Tuning MySQL Performance with MySQLTuner

MySQLTuner is a Perl script that analyzes your MySQL performance and, based on the statistics it gathers, gives recommendations which variables you should adjust in order to increase performance. That way, you can tune your my.cnf file to tease out the last bit of performance from your MySQL server and make it work more efficiently.

Using MySQLTuner

You can download the MySQLTuner script as follows:


In order to run it, we must make it executable:

chmod +x

Afterwards, we can run it. You need your MySQL root password for it:


The script should now run and display various stats and recommendations. Below is a example:


Run OPTIMIZE TABLE to defragment tables for better performance

To optimise all tables in a single database;

mysqlcheck --optimize -p -u user_name database_name

To optimise all tables in all databases;

mysqlcheck --optimize -A -p -u user_name

Repair, check, optimize

mysqlcheck --auto-repair --check --optimize --all-databases


This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

Show Details
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)