[Mysql] acquaintance MySQL

A, MySQL is a client / server architecture is
the default installation directory on the 1) macOS operating systems: / usr / local / mysql / 

  There is a bin directory under the MySQL installation directory, the storage of many executable files in this directory. Path 2) The bin directory is added to the PATH environment variable

  If we feel that each execution of a document must enter a long string of the path name too much trouble, you can add the path to the bin directory where the PATH environment variable. PATH environment variable is a set of paths, use a colon between the various paths: to isolate, say, the value of the PATH environment variable on my machine is: / usr / local / bin: / usr / bin: / bin: / usr / sbin: / sbin 
3) start the MySQL server program
MySQL server used to start the program in a UNIX-like systems have many executable files, mostly in the bin directory of your MySQL installation directory
mysqld 
mysqld executable file represents the MySQL server program, you can run the executable file directly to start a server process. However, this command is not used, we continue to see more Niubi start command down. 

mysqld_safe 
mysqld_safe is a startup script, it will call indirect mysqld, but also another way to start the monitoring process, the monitoring process server process hung up, they can help to restart it. In addition, when using mysqld_safe to start the server program, error messages from the server program and other diagnostic information redirected to a file, resulting in an error log, which can help us to find out why the error occurred. 

mysql.server 
mysql.server also a startup script, it will call indirect mysqld_safe, specify start parameters in the back when you call mysql.server can start the server program, like this: 
mysql.server start 
should be noted that this mysql.server file is actually a link to the file, it is the actual file .. /support-files/mysql.server. MacOS I use the operating system will help us to automatically create a link to the actual file links to files in the bin directory, if your operating system does not automatically help you create that file, you can create yourself a

In addition, we can also use mysql.server command to shut down the server program is running, as long as the start parameters into stop like: mysql.server stop

mysqld_multi
In fact, our computer can run multiple server instances, that is, run multiple MySQL server process. mysql_multi executable files can be monitored start or stop each server process. The use of this command is relatively complex.
4) Start the MySQL client programs
-P port mysql -h hostname -u username -p password
Disconnect quit exit \ q 
 
Second, a select statement which parts of the process will involve

 

 1) Connection Management

  The client process uses TCP / IP to establish a connection with a remote server process, whenever a client process to connect to the server process, the server process creates a thread to deal specifically interact with the client, will be when the client exits disconnected from the server, the server does not immediately interact with the client thread in destroying, but it cached, when another new client and then connect to this thread allocation cache to the new clients. MySQL server will allocate a thread for each incoming client connections, but too much thread allocation will seriously affect system performance, so we need to limit what can be connected to the server at the same time the number of clients.
  When the connection is established, the server threads associated with the client will wait for a request sent by the client, MySQL server receives the request is just a text message, the text message to go through various processes. 
 2) Analysis and optimization
 
1, the query cache
  Although sometimes the query cache can improve system performance, but also have to maintain this cache caused due to some overhead, such as every time the query cache to search queries processed to update the query cache, query cache maintenance of the corresponding memory region. As of MySQL 5.7.20, the query cache is not recommended, and delete MySQL 8.0 in 
2, parsing
  MySQL server program must first do the analysis of this text, if the request for correct syntax, tables, and then from a variety of search criteria in the text you want to query some data are extracted into the internal structure of MySQL servers used up. It involves parsing lexical, syntactic analysis, semantic analysis phase.
3, query optimization
  After parsing, the server program to get the information you need, such as the column is to query which table is which, what, and so the search condition yes. We write MySQL statements may execute efficiency is not very high, MySQL's optimizer will do some optimization of our statement. The result is optimized to generate an execution plan, the execution plan indicates what index should be used to query, order of connection between tables is sawed. We can use the EXPLAIN statement to view the execution plan of a statement.
4. Storage Engine
  As of query optimization server program completed so far, there is no real access to real data tables, MySQL server's data storage and retrieval operations are encapsulated into a storage engine called a module. We know the table is composed of records line by line, but this is only a logical concept, how to represent the physical records, how to read data from the table, how the data is written on a specific physical memory, which is memory engine responsible thing. In order to achieve different functions, MySQL provides a wide variety of storage engine, the specific table storage structure may be different in different storage engine access algorithm may be different. 
  To facilitate the management, people connection management, query cache, parsing, query optimization of these functions do not involve real data storage division for MySQL server function, the function is divided into real access to data storage engine function. Provide a variety of different storage engines to MySQL server layer on top of a unified call interface (that is, the storage engine API), contains dozens of low-level functions, such as under the "first read the index content", "read a index content "," insert record "and so on.
After it is completed in the MySQL server query optimization, simply call the API provided by the underlying storage engine execution plan generation, access to data is returned to the client just fine. The most common is InnoDB and MyISAM.
Related command:
View the current server supports the storage engine
SHOW ENGINES; 

Support column which indicates that the storage engine is available, DEFAULT values ​​represent the current server program is the default storage engine. Comment column is a description of the storage engine, in English, will forward to see. Transactions column represents the storage engine supports transaction processing. XA represents the column with the storage engine supports distributed transactions. Savepoints represents part of the storage engine supports transaction rollback. 

When you create a table designated storage engine
CREATE TABLE 表名(
    Construction of the table statement;
) ENGINE = Storage Engine name;
 
Changes to the table storage engine
ALTER TABLE table storage engine ENGINE = name;
 
View table structure
SHOW CREATE TABLE engine_demo_table 

 

Guess you like

Origin www.cnblogs.com/756623607-zhang/p/12026545.html