Due to a mistake i deleted the log folder for mysql. Is there a way to generate the folder and the error logs? I'm using MariaDB 10.3 on Debian 9 Stretch

  • ignore it, logs will be generated new and if you have an error, it will came again. – nbk May 2 '20 at 12:11
  • 1
    The log file will re-appear when mysqld is restarted, but only if you manually create the folder where it is supposed to be under /var/log, and only if the mysql process has privileges to create a new log file in that folder. If you don't manually re-create the folder with the correct permissions, that won't happen. – Gordan Bobic May 2 '20 at 12:38

mysqld keeps the error log file open. If you delete the file the file handler is still valid and the file is available for the process that opened it (=mysqld).

# lsof  | grep mysqld
mysqld    20163 20192           mysql    2w      REG              253,2       4434         15 /var/log/mysql/error.log

# rm /var/log/mysql/error.log
# lsof  | grep mysqld | grep error
mysqld    20163 20310           mysql    2w      REG              253,2       4549         15 /var/log/mysql/error.log (deleted)

You can get the content of the error log from the /proc filesystem.

# ls -la /proc/20163/fd/ | grep error
l-wx------ 1 mysql mysql 64 May  2 15:49 1 -> /var/log/mysql/error.log (deleted)
l-wx------ 1 mysql mysql 64 May  2 15:49 2 -> /var/log/mysql/error.log (deleted)
# cat /proc/20163/fd/1
2020-05-02T15:49:46.163721Z 0 [Warning] Could not increase number of max_open_files to more than 5000 (request: 65535)
2020-05-02T15:49:46.355461Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.29-0ubuntu0.18.04.1-log) starting as process 20163 ...
2020-05-02T15:49:46.371978Z 0 [Note] InnoDB: PUNCH HOLE support available
2020-05-02T15:49:46.372006Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-05-02T15:49:46.372010Z 0 [Note] InnoDB: Uses event mutexes
2020-05-02T15:49:46.372013Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2020-05-02T15:49:46.372016Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-05-02T15:49:46.372023Z 0 [Note] InnoDB: Using Linux native AIO
2020-05-02T15:49:46.372272Z 0 [Note] InnoDB: Number of pools: 1
2020-05-02T15:49:46.372380Z 0 [Note] InnoDB: Using CPU crc32 instructions
2020-05-02T15:49:46.376119Z 0 [Note] InnoDB: Initializing buffer pool, total size = 384M, instances = 1, chunk size = 128M
2020-05-02T15:49:46.398759Z 0 [Note] InnoDB: Completed initialization of buffer pool
2020-05-02T15:49:46.404255Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-05-02T15:49:46.421829Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2020-05-02T15:49:48.448175Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-05-02T15:49:48.448255Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-05-02T15:49:48.938748Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-05-02T15:49:48.939384Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2020-05-02T15:49:48.939393Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2020-05-02T15:49:48.939823Z 0 [Note] InnoDB: Waiting for purge to start
2020-05-02T15:49:48.990402Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 3292611
2020-05-02T15:49:48.990563Z 0 [Note] InnoDB: Loading buffer pool(s) from /database/mysql/ib_buffer_pool
2020-05-02T15:49:48.990773Z 0 [Note] Plugin 'FEDERATED' is disabled.
2020-05-02T15:49:49.476557Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200502 15:49:49
2020-05-02T15:49:49.569129Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2020-05-02T15:49:49.569147Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-05-02T15:49:49.596450Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-02T15:49:49.596491Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-05-02T15:49:49.616398Z 0 [Note] Server hostname (bind-address): ''; port: 3306
2020-05-02T15:49:49.616425Z 0 [Note]   - '' resolves to '';
2020-05-02T15:49:49.616456Z 0 [Note] Server socket created on IP: ''.
2020-05-02T15:49:49.856411Z 0 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MySQL server acts as a slave and has his hostname changed!! Please use '--relay-log=produ-data-db-0000-05f01-use2-relay-bin' to avoid this problem.
2020-05-02T15:49:49.946618Z 1 [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2020-05-02T15:49:49.966480Z 2 [Warning] Slave SQL for channel '': If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2020-05-02T15:49:49.966566Z 2 [Note] Slave SQL thread for channel '' initialized, starting replication in log 'mysql-bin.000116' at position 2493, relay log './produ-data-db-0000-05f01-use2-relay-bin.000002' position: 1811
2020-05-02T15:49:49.971887Z 1 [Note] Slave I/O thread for channel '': connected to master 'replication@produ-data-db-0000-0c5f4-use2:3306',replication started in log 'mysql-bin.000116' at position 2493
2020-05-02T15:49:51.066602Z 0 [Note] Event Scheduler: Loaded 0 events
2020-05-02T15:49:51.066831Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.29-0ubuntu0.18.04.1-log'  socket: '/var/lib/mysql-files/mysql.sock'  port: 3306  (Ubuntu)
2020-05-02T15:50:05.681566Z 5 [Warning] IP address '' could not be resolved: Name or service not known

Same way you can get other files (slow log, general log). However if the files were closed and were deleted - you're pretty much out of luck (not saying it's impossible to recover, but hard).


I'm not sure what you mean by "generate", but you can just create it. Make sure it is owned by the mysql user. When you restart mysqld, the error log will get re-created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.