From compilation to tools: several mysql optimization methods _ MySQL

Source: Internet
Author: User
Tags mysql manual
From compilation to tools: several mysql optimization methods I. optimizing mysql during compilation
If you distribute and install mysql from the source code, note that the compilation process will have an important impact on the future target program. different compilation methods may obtain similar target files, however, the performance may vary greatly. Therefore, when compiling and installing mysql, you must carefully select the most likely compilation option based on your application type. This custom mysql can provide the best performance for your applications.
Tip: select a good compiler and a good compiler option, so that the application can improve performance by 10-30%. (Mysql document)

1.1 Use the pgcc (pentium gcc) compiler
The compiler (http://www.goof.com/pcg/) optimizes programs running on the Pentium processor system and compiles mysql source code with pgcc, improving the overall performance by 10%. Of course, if your server does not use a Pentium processor, you do not need to use it because it is designed for the Pentium system.

1.2 compile mysql using only the character set you want to use
Mysql currently provides up to 24 different character sets for global users to insert or view data in tables in their own language. However, the best choice is to select a character set that you need. For example, disable all character sets except latin1:
------------------------------------------------------------------------------
%>./Configure-with-extra-charsets = none [-- other-configuration-options]
------------------------------------------------------------------------------

1.3 Compile mysqld into a static execution file.
Compiling mysqld into a static execution file can achieve better performance without sharing the database. You can statically compile mysqld by specifying the following options during configuration.
------------------------------------------------------------------------------
%>./Configure-with-mysqld-ldflags =-all-static [-- other-configuration-options]
------------------------------------------------------------------------------

1.4 configuration samples
The following configuration commands are commonly used to improve performance:
------------------------------------------------------------------------------
%> Cflags = "-o6-mpentiumpro-fomit-frame-pointer" cxx = gcc cxxflags = "-o6-mpentiumpro-fomit-frame-pointer-felide-constructors-fno-restrictions tions -fno-rtti ". /configure -- prefix =/usr/local -- enable-validator -- with-mysqld-ldflags =-all-static -- disable-shared
------------------------------------------------------------------------------

II. server adjustment
It is important to ensure correct compilation, but this is only the first step of success. configuring many mysql variables also plays a key role in the normal operation of the server. You can assign values to these variables in a configuration file to make sure they take effect every time you start mysql. this configuration file is my. cnf.
Mysql has provided several samples of my. cnf files, which can be found in the/usr/local/mysqld/share/mysql/directory. These files are named my-small.cnf, my-medium.cnf, my-large.cnf, and my-huge.cnf, which can be found in the title of the system type that describes the configuration file to apply. If you run mysql on a system with only a small amount of memory and only use it occasionally, the my-small.cnf would be ideal because it commands mysqld to use only the fewest resources. Similarly, if you plan to build an e-commerce supermarket and the system has 2 GB of memory, you may need to use mysql-huge.cnf files.
To use one of these files, you need to copy the most suitable file and change it to my. cnf. You can choose one of the following three scopes:
Global: Copy the my. cnf file to the/etc directory of the server, so that the variables in the configuration file apply to the global environment, that is, they are valid for mysql database servers on all servers.
Local: copy the my. cnf file to the [mysql-install-dir]/var/directory so that my. cnf acts on a specific server. [Mysql-install-dir] indicates the mysql installation directory.
User: you can restrict specific users to copy my. cnf to the user's root directory.
How can I set these variables in my. cnf? Further, you can set the variable. Although the variables used are relatively common to mysql servers, each variable has a more specific relationship with some components of mysql. For example, the variable max_connects belongs to the mysqld category. Run the following command:
------------------------------------------------------------------------------
%>/Usr/local/mysql/libexec/mysqld -- help
------------------------------------------------------------------------------
It displays a large number of options and variables related to mysqld. You can easily find the variable under this line of text:
------------------------------------------------------------------------------
Possible variables for option -- set-variable (-o) are
------------------------------------------------------------------------------
Then you can set the variables in my. cnf as follows:
------------------------------------------------------------------------------
Set-variable = max_connections = 100
------------------------------------------------------------------------------
It sets the maximum number of concurrent connections of the mysql server to 100. Make sure to insert variable settings under the [mysqld] title in the my. cnf file.

III. table type
Many mysql users may be surprised that mysql does provide users with 5 different table types, such as dbd, heap, isam, merge, and myiasm. Dbd is classified as transaction security, while others are non-transaction security.

3.1. transaction security
Dbd
The berkeley db (dbd) table is a table that supports transaction processing, developed by sleepycat (http://www.sleepycat.com. It provides the long-awaited mysql feature-transaction control. Transaction control is a very valuable feature in any database system, because they ensure that a group of commands can be successfully executed.

3.2 Non-transaction security
Heap
The heap table is the fastest table to access data in mysql. This is because they use a hash index stored in dynamic memory. Another key point is that if mysql or the server crashes, data will be lost.

Isam
Isam tables are the default table types of earlier mysql versions until myiasm is developed. We recommend that you do not use it any more.

Merge
Merge is an interesting new type that appears after 3.23.25. A merge table is actually a set of identical myisam tables and is merged into a table mainly for efficiency reasons. This improves speed, search efficiency, repair efficiency, and saves disk space.

Myiasm
This is the default table type of mysql. It is based on iasm code, but there are many useful extensions. Why is myiasm better:
Myiasm tables are smaller than iasm tables, so fewer resources are used.
Myiasm tables can be transplanted at the binary layer on different platforms.
Larger key size, larger key size limit.

3.3 specify the table type
You can specify the table type when creating a table. In the following example, create a heap table:
------------------------------------------------------------------------------
Mysql> create table email_addresses type = heap (
-> Email char (55) not null,
-> Name char (30) not null,
-> Primary key (email ));
------------------------------------------------------------------------------
Bdb tables require some configuration work. For more information, see http://www.mysql.com/doc/ B /d/bdb_overview.html.

3.4. more table types.
To make mysql management more interesting, mysql 4.0 will provide two new table types, innobase and gemeni.

IV. optimization tools
The mysql server itself provides several built-in commands to help with optimization.

4.1. show
You may be interested in knowing what the mysql server actually has. the following command provides a summary:
------------------------------------------------------------------------------
Mysql> show status;
------------------------------------------------------------------------------
It provides a fairly long list of state variables and their values. Some variables include the number of customers with exceptional termination, the number of connections with exceptional termination, the number of connection attempts, the maximum number of concurrent connections, and a large amount of other useful information. This information is of great value for identifying system problems and inefficiency.
Show can do more. It can display valuable information about log files, specific databases, tables, indexes, processes, and permission tables. For more information, see the mysql manual.

4.2. explain
When you are facing a select statement, explain how the select command is processed. This is not only helpful for deciding whether to add an index, but also for determining how a complicated join is processed by mysql.

4.3 optimize
The optimize statement allows you to restore space and merge data file fragments. This is especially important after a large number of updates and deletions are performed on tables that contain long rows. Optimize currently only works in myiasm and bdb tables.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.