About User Rights
User rights are acquired after the connection is established. This means that the administrator changes the user’s permissions after the user obtains the connection. The connection permissions obtained by this user will not be renewed.
About the connection
After the connection is complete, it is idle when not in use. When a connection is idle for a long time, the connector automatically disconnects it. This parameter is controlled by wait_timeout and defaults to 8 hours. The database persistent connection means that the client uses the same connection continuously after obtaining the connection. A short connection is when a connection is disconnected after a few queries are executed and then re-established the next time the query is executed. Establishing a connection is a complex operation, and long connections are usually used.
Problems with using long connections
The temporary memory used by mysql is managed in connection objects. These resources are released when the connection is disconnected. If long connections accumulate, the system may use too much memory and kill them forcibly (triggering OOM). In this case, mysql restarts abnormally. So how to solve this problem? There are two options:
- Disconnect long connections periodically. Disconnect after a certain amount of time, or after the program determines that a large memory – consuming query has been executed.
- With mysql 5.7 and later, after an operation that consumes too much memory, initialize the connection resource by executing mysql_reset_connection.