Announcement Module
No announcement yet.

MySQL Optimal Settings

Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL Optimal Settings

    Hi all

    I need all your advices regarding the performance of my Database. Our database was running fine and now it is lagging when there are more users.

    Let me explain

    We are using MySQL 4.0

    1.We have tables having records more than 100,000

    2.Our tables are growing by min 200 records per day

    3.We have applied index for frequent usage and huge table.

    4.We have modified the my.ini file to use the max resources

    5.Our database server is running on a Windows 2000 server with 1 GB RAM

    Still , the site is lagging and the MySql database residing server is showing 100% CPU usage.

    So please, help me if our procedure are correct and any thing we are missing.

    All advices are highly valued and please help

    Thank you all

  • #2
    I would start with the slow query log to see whats happening.


    • #3
      Thanks linuxrunner for the replay )

      1.Yes i do checked slow queries,
      2.I have few queries of 3-5 seconds execution time.
      3.I have optimized some of them
      4.The are 2 tables , one OrderMaster, and other OrderDetail
      the SQL running on this tables are slower.

      5.They have index for the search fields in this tables
      6.The master tbl have 116,524 Recs,
      and detail tbl have 453,465 recs
      7.And also we have applications accessing these tables in
      regular time interval
      8. So these tables are busy.
      9.Since these tables have all data , and we only use data not
      older than 3 months ,
      10.Is it a best idea to remove those unused data to archive DB.
      11.Thus making these tables less weight
      12.Will produce better response time
      13 Or is there any other setting or consideration we have to change to get better response time and reduce CPU usage.

      expecting the reply soon , pls

      thank you


      • #4
        Are you sure your indexes are on the correct columns? indexes on columns with high null counts or low cardinality can often worsen your performance. also, if you're creating an order by on a large body of results, you'll see slow downs as sometimes the sorts will result in disk based creations of MyISAM tmp tables to order your data before sending it to your app. Make sure your query only includes the columns you need (not * if you dont need everything) and eliminate large bodies of info when possible by showing only the most recent results. If you're getting a lot of traffic you might try farming out all your select statements to a clustered server with MyISAM tables instead of INNODB table types.


        • #5
          Thanks JGilbert for the information and replay
          1. I have only indexed the fields which is used mostly for search and these fields are NOT NULL, the orderno and customerno fields.

          2. As i mentioned in earlier post,
          There are other sub applications which checks the 'order master' and 'order detail' tables for changes, regularly for every 5 secs.
          These regular queries in this applications are slower and takes larger CPU time.

          Iam using MyISAM type Tables ,
          Is there any other setting , that i can work on.

          thanks and reply


          • #6

            can you post output of SHOW VARIABLES and SHOW GLOBAL STATUS?

            Also what is the size of your database?


            • #7
              Hai tanj

              The database size is about 120 MB
              The MySQL version is 4.0.17

              expecting your reply
              Thank You

              This are the variables

              Show Variables Listing

              'character_sets','latin1 big5 czech euc_kr gb2312 gbk latin1_de sjis tis620 ujis dec8 dos german1 hp8 koi8_ru latin2 swe7 usa7 cp1251 danish hebrew win1251 estonia hungarian koi8_ukr win1251ukr greek win1250 croat cp1257 latin5'
              'ft_boolean_syntax','+ -><()~*:""&|'
              'timezone','Arab Standard Time'
              'version_comment','Source distribution'


              • #8
                What are your stats for table locks? are you seeing long table lock times in your slow query log?


                • #9

                  thanks for posting Status variables. Can you also post SHOW STATUS output so I would see where the performance bottlenecks could be?

                  120MB is quite small size for database and I'm used to play with tables having 4 million records or more. So it should be no problem for your config )

                  I suspect that your database usage may have bad joins or table scans. But I need output of SHOW STATUS or slow query log for this.



                  • #10
                    Hi tanj
                    Thank tanj
                    Below are the Status values , these values not at peak , took them at morning .

                    # Query:
                    # show status


                    • #11
                      Hi JGilbert
                      Thank You

                      I checked the slowquery log , The Lock time is 0 , even for slow queries.

                      thank you


                      • #12
                        The Lock Time field in the slow query log represents how long it had to wait to obtain a lock, not how long it held a lock. What's important is how long the query execution took and how many rows it had to look at to return the result.


                        • #13
                          Thank You
                          for the information linuxrunner,
                          Hoping more help

                          Thank You


                          • #14
                            Hello mimayls

                            Thanks for the status values, it proves instructive.


                            Is showing that your queries are doing, most of the time, table scans instead of index reads. Looks like you'll have to review most of your queries' execution plans (i.e. take the queries and EXPLAIN on them). Maybe you will want to post some examples of query and EXPLAIN query so I could give you more advice.

                            About the configuration, you might want to increase the tmp_table_size to 64M (it shows that you have a lot of on-disk temporary tables created)

                            Also I see that your query cache size is 256M, but only 1M is used. It's way too large. In regards to your database size I recommend that you set query_cache_size to 8M, so you will free unnecessary reserved memory.



                            • #15
                              Hai tanj
                              Thank you for the suggections.

                              Can you please tell me
                              1.why query cache is used only 1MB,
                              Because query are small size Or There is another problem

                              2.Why there are large no. of tmp tables
                              This is the problem of the unoptimized queries?
                              Lack of indexes in the table

                              please guid me

                              Thank You