ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Basic MySQL Performance Tips

Updated on August 18, 2010

Basic MySQL Performance Tuning

This article highlights some basic MySQLperformance features that you may or may not know about. This is really a beginners article, and does not go into great detail about further optimisations that are possible with MySQL. As a database and web developer for over 10 years I have worked with both Microsoft SQL Server and MySQL and I have compiled a list of essential performance tips which I hope you find useful.

MySQL Database Specific

Data Types - Use The Correct Type


Use the most appropriate data type for your fields. Do not use large integer columns when you are only storing 3 or 4 digit numbers. Larger data types require more memory therefore its slower to process. Stick with medium it or small int columns unless you are sure you will need the larger int type.

The same applies to character types, keep your length as small as possible.

Store Text Columns in Seperate Tables

Its better to save your text columns in seperate tables and only query the data when you need it. This keeps the footprint of your frequently used tables small and speeds up insert and update operations.

Add Appropriate Indexes

A frequent cause of slowdown is lack of indexes on a table. Indexes allowing for much quicker searching for data, and eliminates slow table scans. You should identify columns for indexing and add indexes to frequently searched columns.

Choose The Correct Engine - MYISAM or INNODB

MYISAM is fastest, and supports Full Text Indexes, whilst InnoDB is transactional and does not support full text indexes. You can mix and match table types within the same database so design your application to take advantage of the different engines. Use MEMORY tables for storing data that its OK to lose if the server is stopped but do not store large tables in MEMORY.

Use Partitioning To Improve Data Access Speed

Recent versions of MySQL support partitioning. Your data can be split into seperate physical data files and spread onto different disks. This greatly improves many operations such as read speed, update speed and join query performance. Do not partition your data immediately - wait until you have some real data to look at before you identify suitable fields for partitioning. For example in a order management application you may want to partition orders by year. Orders that are rarely searched for e.g. 3 or 4 years ago will not slow down your queries for the latest data.

Follow Normalisation Rules

Ensure your data is well normalised. Database join operations are much faster than table scans, and if you have a large number of rows, your qury will run much faster if you do not have to scan lots of un-normalised text fields. Identify suitable areas for normalisation and follow standard 1, 2 and 3 normal form to optimise

Application Performance Tips

Use The Latest Data Access Layers

Make sure you use the most up to date Data Access drivers for example the current version of the .NET connector for MySQL is 6.2.3.  With every connector release, there are usually small performance improvements.

Avoid Select * Queries

Yes, this old chestnut.  Avoid SELECT * queries.  You will save traffic between application and database by only selecting the columns you need.

Cache Data That Rarely Changes

If you data is static, only update every so often.  Choose a good cache strategy to maximise your applications speed.

Hardware Performance

Assuming all is equal, faster hardware will almost always mean faster database response. So find the fastest server your budget allows. If you are a basic user don't worry, for small tables basic shared hosting is usually more than enough for simple MySQL databases and you can always scale later.

  • Ensure your database server has enough RAM. MySQL caches its queries in memory and the more memory available to do this the better. You can configure some settings in the MySQL config to tell MySQL how much RAM to use for the query cache.
  • If possible store your database files on fast access disk drives, such as a fibre attached drive array. The faster your disk response times that quicker your database access will be.
  • Install a MYSQL cluster for superior performance. Spread processor load across multiple servers for true high end performance. MySQL recently released MySQL Server with Cluster support for Windows platforms.
  • Use a dedicated MySQL server , if budget allows, with MYSQL set to use 90% of the memory.  A server that also does many other tasks will be unable to dedicated CPU to MySQL all of the time.
  • MySQL provide a 64 Bit option - always use this is your operating system and hardware allows as there is a performance improvement.
  • If you are installing a new Server, use the latest Core i7 or AMD opteron CPUs.  These have multiple cores and large on chip caches, perfect for high performance database number crunching.

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com 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: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    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 googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    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)
    Marketing
    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.
    Statistics
    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)