Python access to MySQL database is slow

I wrote an assignment in the past two days about the student selection system, which will be posted on my blog after completion. The roommate's access speed is almost milliseconds, and I have to wait at least four or five seconds. The main reasons that I summarized that affect the access speed are as follows:

1. Host name
2. Repeatedly open and close the database
3. There is too much data in the back-end database, and the back-end query data is very slow because of no data optimization.

Solution:

1. Replace localhost with IP address:mysql -h 127.0.0.1 -uroot -p

2. MySQL is forbidden to do domain name resolution: When MySQL is processing a new thread connection request, it will try to perform DNS resolution. If
it cannot be found in the host cache and Hosts, the processing will be slow.
Therefore, the most straightforward and easy way is to disable it. reverse lookup feature, you can modify the MySQL configuration file to achieve, under Linux is my.cnf file under windows is my.ini file, configuration
add the following line of code at the file [mysqld]: skip-name-resolve
then restart the MySQL service, to connect again It was found that it was even seconds.
The disadvantage of this scheme is that in the future, when using grant to authorize users, only the IP format can be used instead of the host name.

It can also be achieved by modifying the system hosts file. For example, I want to solve the problem of slow remote connection to the MySQL server at 192.168.1.100. I only need to add a new record in the hosts file of the server where the MySQL library is located as follows: 192.168.1.100
test.com Save and exit, and connect to the MySQL database remotely again, which is also very fast. The reason for this is that the
remote connection speed of 192.168.1.100 that you added to the record has become faster, and the connection speed of other hosts is as slow as before. This method can also solve the problem of slow response when ssh connects to a host remotely, and the principle is the same.

3. Open the database once, and close the cursor after all database operations are completed, which can also speed up the access speed relatively.

Guess you like

Origin blog.csdn.net/m0_46202060/article/details/109990103