Eu tenho um problema estranho com o MySQL em um servidor Debian (Jessie).
Quando o servidor for reiniciado, o systemd tentará iniciar o mysqld, mas ele falhará (parece que a porta 3306 já está sendo usada, mas não vejo por que isso ocorreria).
No entanto, se eu enviar o SSH para o servidor apenas alguns minutos depois e executar sudo systemctl start mysql
, ele será bem-sucedido.
O problema pode ser reproduzido toda vez que eu reiniciar o servidor.
Alguém já teve esse problema, ou alguma adivinha o que poderia impedir que o MySQL iniciasse corretamente? Eu poderia adicionar um atraso antes de iniciar o MySQL após a reinicialização, mas gostaria de entender o que está acontecendo e, na verdade, não tenho certeza se isso resolveria o problema.
Aqui está o resultado de sudo systemctl status mysql -l
após a reinicialização:
● mysql.service - LSB: Start and stop the mysql database server daemon
Loaded: loaded (/etc/init.d/mysql)
Active: failed (Result: exit-code) since Fri 2017-09-01 21:54:44 CEST; 1min 41s ago
Process: 581 ExecStart=/etc/init.d/mysql start (code=exited, status=1/FAILURE)
Sep 01 21:54:06 gimli systemd[1]: Starting LSB: Start and stop the mysql database server daemon...
Sep 01 21:54:44 gimli mysql[581]: Starting MySQL database server: mysqld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . failed!
Sep 01 21:54:44 gimli systemd[1]: mysql.service: control process exited, code=exited status=1
Sep 01 21:54:44 gimli systemd[1]: Failed to start LSB: Start and stop the mysql database server daemon.
Sep 01 21:54:44 gimli systemd[1]: Unit mysql.service entered failed state.
e o log correspondente de /var/log/mysql/error.log
170901 21:54:16 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170901 21:54:16 [Note] Plugin 'FEDERATED' is disabled.
170901 21:54:17 InnoDB: The InnoDB memory heap is disabled
170901 21:54:17 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170901 21:54:17 InnoDB: Compressed tables use zlib 1.2.8
170901 21:54:17 InnoDB: Using Linux native AIO
170901 21:54:17 InnoDB: Initializing buffer pool, size = 128.0M
170901 21:54:17 InnoDB: Completed initialization of buffer pool
170901 21:54:17 InnoDB: highest supported file format is Barracuda.
170901 21:54:22 InnoDB: Waiting for the background threads to start
170901 21:54:23 InnoDB: 5.5.57 started; log sequence number 351234412
170901 21:54:23 [Note] Server hostname (bind-address): '192.168.1.14'; port: 3306
170901 21:54:23 [Note] - '192.168.1.14' resolves to '192.168.1.14';
170901 21:54:23 [Note] Server socket created on IP: '192.168.1.14'.
170901 21:54:23 [ERROR] Can't start server: Bind on TCP/IP port: Cannot assign requested address
170901 21:54:23 [ERROR] Do you already have another mysqld server running on port: 3306 ?
170901 21:54:23 [ERROR] Aborting
170901 21:54:23 InnoDB: Starting shutdown...
170901 21:54:24 InnoDB: Shutdown completed; log sequence number 351234412
170901 21:54:24 [Note] /usr/sbin/mysqld: Shutdown complete
No entanto, se eu executar sudo systemctl start mysql
manualmente, ele funcionará corretamente:
170901 22:01:36 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
170901 22:01:36 [Note] Plugin 'FEDERATED' is disabled.
170901 22:01:36 InnoDB: The InnoDB memory heap is disabled
170901 22:01:36 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170901 22:01:36 InnoDB: Compressed tables use zlib 1.2.8
170901 22:01:36 InnoDB: Using Linux native AIO
170901 22:01:36 InnoDB: Initializing buffer pool, size = 128.0M
170901 22:01:36 InnoDB: Completed initialization of buffer pool
170901 22:01:36 InnoDB: highest supported file format is Barracuda.
170901 22:01:36 InnoDB: Waiting for the background threads to start
170901 22:01:37 InnoDB: 5.5.57 started; log sequence number 351234412
170901 22:01:37 [Note] Server hostname (bind-address): '192.168.1.14'; port: 3306
170901 22:01:37 [Note] - '192.168.1.14' resolves to '192.168.1.14';
170901 22:01:37 [Note] Server socket created on IP: '192.168.1.14'.
170901 22:01:37 [Note] Event Scheduler: Loaded 0 events
170901 22:01:37 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.57-0+deb8u1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Debian)
No meu conhecimento, o script systemd não foi modificado (é o que vem com o pacote Debian mysql) e, até onde eu sei, ele nunca funcionou corretamente. A porta 3306 não deve ser usada por outro processo.