Mysql server fails to start

I used this minimal configuration:

services.mysql = {
  enable = true;
  package = pkgs.mysql80;
};

and get this (to me not very meanigful) error:

building Nix...
building the system configuration...
stopping the following units: accounts-daemon.service
activating the configuration...
setting up /etc...
reloading user units for ford...
restarting sysinit-reactivation.target
reloading the following units: dbus.service
restarting the following units: polkit.service
starting the following units: accounts-daemon.service
the following new units were started: NetworkManager-dispatcher.service
warning: the following units failed: mysql.service
× mysql.service - MySQL Server
     Loaded: loaded (/etc/systemd/system/mysql.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Sun 2025-10-19 15:09:30 CEST; 307ms ago
 Invocation: bf5b518c231c4077b65987f0521603a2
    Process: 7388 ExecStartPre=/nix/store/g7dx3l8f46jvh27ymmlf37aly2cs8gcv-unit-script-mysql-pre-start/bin/mysql-pre-start (code=exited, status=0/SUCCESS)
    Process: 7405 ExecStart=/nix/store/4y2r8kwhbypcrsj92kpabjzlfawanqg1-unit-script-mysql-start/bin/mysql-start (code=exited, status=1/FAILURE)
   Main PID: 7405 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete"
      Error: code: 22 (Invalid argument)
         IP: 0B in, 0B out
         IO: 36.4M read, 0B written
   Mem peak: 287.5M
        CPU: 671ms

Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.951587Z 1 [ERROR] [MY-012237] [InnoDB] Corrupted page [page id: space=0, page number=0] of datafile './ibdata1' could not be found in the doublewrite buffer.
Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.951608Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Data structure corruption.
Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.952160Z 1 [ERROR] [MY-011013] [Server] Failed to initialize DD Storage Engine.
Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.952622Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.952658Z 0 [ERROR] [MY-010119] [Server] Aborting
Okt 19 15:09:30 mave mysql-start[7405]: 2025-10-19T13:09:30.954515Z 0 [System] [MY-010910] [Server] /nix/store/k252dxzzfb24npqjb45bpj1qym0d9pcv-mysql-8.0.43/bin/mysqld: Shutdown complete (mysqld 8.0.43)  Source distribution.
Okt 19 15:09:30 mave systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Okt 19 15:09:30 mave systemd[1]: mysql.service: Failed with result 'exit-code'.
Okt 19 15:09:30 mave systemd[1]: Failed to start MySQL Server.
Okt 19 15:09:30 mave systemd[1]: mysql.service: Consumed 671ms CPU time, 287.5M memory peak, 36.4M read from disk.
warning: error(s) occurred while switching to the new configuration

Same with mysql84 package, but works with mariadb. but that seems to be incompatible with mysql-workbench.

I suspect you ran it once and it worked. When running for the first time it creates files in /var/lib/mysql. When you change the version afterwards the new version is not compatible with the existing data hence it fails.

2 Likes

It worked. I tried this before and have no clue whats different now tbh.

With the failed service my mysql-workbench did reconize the server, now it fails to connect. sets nixos a password for the user?

You might want to look at services.mysql.ensureUsers.