MySQL
Установка
Базовые команды
Выгрузка и загрузка дампа
Уровни изоляции транзакций
- READ UNCOMMITTED
- После INSERT данные сразу-же станут доступны для чтения.
- READ COMMTITED
- В данном случае прочитать данные возможно только после вызова COMMIT. При чем внутри транзакции данные тоже будут еще не доступны.
- REPEATABLE READ
- Здесь может возникнуть теоретическая проблема «фантомного чтения». Когда внутри одной транзакции происходит чтение данных, другая транзакция в этот момент вставляет новые данные, а первая транзакция снова читает те-же самые данные.
- SERIALIZABLE
- На данном уровне MySQL блокирует каждую строку над которой происходит какое либо действие, это исключает появление проблемы «фантомов».
MySQL server has gone away
Разберемся раз и навсегда.
Эта секция покрывает также ошибку Lost connection to server during query error.
Самая частая причина для ошибки MySQL server has gone away это то что сервер закрыл соединение по таймауту. В этом случае вы обычно получите одну из следующих ошибок(в зависимости от вашей ОС):
- CR_SERVER_GONE_ERROR - Клиент не смог отправить запрос
- CR_SERVER_LOST - Клиент не получил ошибку во время записи на сервере, но и при этом не получил ответ(или полный ответ) на запрос.
По умолчанию сервер закрывает соединение после 8ми часов если ничего не происходит. Вы можете поменять это ограничение в переменной wait_timeout, когда запускаете mysqld. См. секцию "Server System Variables" в документации.
Если у вас есть скрипт, вы должны сделать автоматическое переподключение и запустить запрос снова. Это предполагает, что со стороны клиента переподключение включено(оно включено для консольного клиента mysql).
Some other common reasons for the MySQL server has gone away error are:
- You (or the db administrator) has killed the running thread with a KILL statement or a mysqladmin kill command.
- You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
- A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
- You got a timeout from the TCP/IP connection on the client side. This may happen if you have been using the commands: mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...) or mysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...). In this case increasing the timeout may help solve the problem.
- You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).
- You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.
- The problem on Windows is that in some cases MySQL does not get an error from the OS when writing to the TCP/IP connection to the server, but instead gets the error when trying to read the answer from the connection.
- The solution to this is to either do a mysql_ping() on the connection if there has been a long time since the last query (this is what Connector/ODBC does) or set wait_timeout on the mysqld server so high that it in practice never times out.
- You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 64MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.4.2.9, “Packet Too Large”.
- An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.
- It is also possible to see this error if host name lookups fail (for example, if the DNS server on which your server or network relies goes down). This is because MySQL is dependent on the host system for name resolution, but has no way of knowing whether it is working—from MySQL's point of view the problem is indistinguishable from any other network timeout.
- You may also see the MySQL server has gone away error if MySQL is started with the skip_networking system variable enabled,
- Another networking issue that can cause this error occurs if the MySQL port (default 3306) is blocked by your firewall, thus preventing any connections at all to the MySQL server.
- You can also encounter this error with applications that fork child processes, all of which try to use the same connection to the MySQL server. This can be avoided by using a separate connection for each child process.
- You have encountered a bug where the server died while executing the query.
You can check whether the MySQL server died and restarted by executing mysqladmin version and examining the server's uptime. If the client connection was broken because mysqld crashed and restarted, you should concentrate on finding the reason for the crash. Start by checking whether issuing the query again kills the server again. See Section B.4.3.3, “What to Do If MySQL Keeps Crashing”.
You can obtain more information about lost connections by starting mysqld with the log_error_verbosity system variable set to
3. This logs some of the disconnection messages in the hostname.err file. See Section 5.4.2, “The Error Log”.
If you want to create a bug report regarding this problem, be sure that you include the following information:
Indicate whether the MySQL server died. You can find information about this in the server error log. See Section B.4.3.3, “What to Do If MySQL Keeps Crashing”.
If a specific query kills mysqld and the tables involved were checked with CHECK TABLE before you ran the query, can you provide a reproducible test case? See Section 29.5, “Debugging and Porting MySQL”.
What is the value of the wait_timeout system variable in the MySQL server? (mysqladmin variables gives you the value of this variable.)
Have you tried to run mysqld with the general query log enabled to determine whether the problem query appears in the log? (See Section 5.4.3, “The General Query Log”.)
See also Section B.4.2.10, “Communication Errors and Aborted Connections”, and Section 1.7, “How to Report Bugs or Problems”.