Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mariadb: change location configuration file to /etc/my.cnf #51314

Merged
merged 1 commit into from Dec 7, 2018

Conversation

@Izorkin
Copy link
Contributor

Izorkin commented Dec 1, 2018

Motivation for this change

Change location configuration file to /etc/my.cnf
Required for normal works mysql utilities.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Infinisil

This comment has been minimized.

Copy link
Member

Infinisil commented Dec 2, 2018

Required for normal works mysql utilities.

Can you expand on that? Why is this needed? Preferably also add this in the commit message.

@Mic92
Mic92 approved these changes Dec 2, 2018
@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Dec 2, 2018

It is more convenient to view/edit my.cnf in default and static location.
mysql, mysql_install_db, mariabackup are looking by default for my.cnf in /etc. After this change, one does not need to always specify --defaults-extra-file, to point the utilities to non-default location of my.cnf.

@Izorkin Izorkin force-pushed the Izorkin:mariadb-my.cnf branch to 953be3e Dec 2, 2018
@Izorkin Izorkin changed the title mariadb: change location my.cnf mariadb: change location configuration file to /etc/my.cnf Dec 2, 2018
@grahamc grahamc merged commit ca3f089 into NixOS:master Dec 7, 2018
9 checks passed
9 checks passed
grahamcofborg-eval ^.^!
Details
grahamcofborg-eval-check-meta config.nix: checkMeta = true
Details
grahamcofborg-eval-nixos-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./nixos/release.nix -A manual
Details
grahamcofborg-eval-nixos-options nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./nixos/release.nix -A options
Details
grahamcofborg-eval-nixpkgs-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A manual
Details
grahamcofborg-eval-nixpkgs-tarball nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A tarball
Details
grahamcofborg-eval-nixpkgs-unstable-jobset nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A unstable
Details
grahamcofborg-eval-package-list nix-env -qa --json --file .
Details
grahamcofborg-eval-package-list-no-aliases nix-env -qa --json --file . --arg config { allowAliases = false; }
Details
@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Dec 7, 2018

Thanks!

@Izorkin Izorkin deleted the Izorkin:mariadb-my.cnf branch Dec 7, 2018
@andir

This comment has been minimized.

Copy link
Member

andir commented May 17, 2019

By the looks of it this seems to have broken the mysqlReplication test:
https://hydra.nixos.org/build/85547230

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 17, 2019

@andir this correction method will do?

diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 89291d4438f..a98bacf3a75 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -289,6 +289,7 @@ in
       ${optionalString (cfg.bind != null) "bind-address = ${cfg.bind}" }
       ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin=mysql-bin"}
       ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "server-id = ${toString cfg.replication.serverId}"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "slave-skip-errors = 1062"}
       ${optionalString (cfg.ensureUsers != [])
       ''
         plugin-load-add = auth_socket.so
@flokli

This comment has been minimized.

Copy link
Contributor

flokli commented May 17, 2019

@Izorkin I once tried that too, and this gets the vm test to succeed, but as @grahamc mentioned, this is a terrible hack - we can't just ignore all duplicate keys errors on slave replication.

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 17, 2019

@flokli @andir please check this variant

diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 89291d4438f..de313d0c454 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -318,7 +318,7 @@ in
             if ! test -e ${cfg.dataDir}/mysql; then
                 mkdir -m 0700 -p ${cfg.dataDir}
                 chown -R ${cfg.user} ${cfg.dataDir}
-                ${mysql}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${installOptions}
+                ${mysql}/bin/mysql_install_db ${installOptions}
                 touch /tmp/mysql_init
             fi

How to leave the parameter mysql_install_db --defaults-file=/etc/my.cnf in non replication mode?

@flokli

This comment has been minimized.

Copy link
Contributor

flokli commented May 17, 2019

Interresting - this seems to work indeed!

@Izorkin, can you explain why we should not pass /etc/my.cnf to mysql_install_db?

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 18, 2019

@flokli need create new db without log-bin=mysql-bin
example

diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 89291d4438f..a200cab4ba1 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -281,6 +281,13 @@ in

     environment.systemPackages = [mysql];

+    environment.etc."my-test.cnf".text =
+    ''
+      [mysqld]
+      port = 3306
+      datadir = /var/lib/mysql
+    '';
+
     environment.etc."my.cnf".text =
     ''
       [mysqld]
@@ -288,6 +295,8 @@ in
       datadir = ${cfg.dataDir}
       ${optionalString (cfg.bind != null) "bind-address = ${cfg.bind}" }
       ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin=mysql-bin"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin-index=mysql-bin.index"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "relay-log=mysql-relay-bin"}
       ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "server-id = ${toString cfg.replication.serverId}"}
       ${optionalString (cfg.ensureUsers != [])
       ''
@@ -318,7 +327,7 @@ in
             if ! test -e ${cfg.dataDir}/mysql; then
                 mkdir -m 0700 -p ${cfg.dataDir}
                 chown -R ${cfg.user} ${cfg.dataDir}
-                ${mysql}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${installOptions}
+                ${mysql}/bin/mysql_install_db --defaults-file=/etc/my-test.cnf ${installOptions}
                 touch /tmp/mysql_init
             fi

I do not know how to fix it

And need to add replication
--log-basename = master/slave1/slave2
--relay-log=mysqld-relay-bin
https://mariadb.com/kb/en/library/setting-up-replication/

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 18, 2019

Normally this variant?

diff --git a/nixos/modules/services/databases/mysql.nix b/nixos/modules/services/databases/mysql.nix
index 89291d4438f..a63b8956518 100644
--- a/nixos/modules/services/databases/mysql.nix
+++ b/nixos/modules/services/databases/mysql.nix
@@ -287,7 +287,9 @@ in
       port = ${toString cfg.port}
       datadir = ${cfg.dataDir}
       ${optionalString (cfg.bind != null) "bind-address = ${cfg.bind}" }
-      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin=mysql-bin"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin=mysql-bin-${toString cfg.replication.serverId}"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "log-bin-index=mysql-bin-${toString cfg.replication.serverId}.index"}
+      ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "relay-log=mysql-relay-bin"}
       ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "server-id = ${toString cfg.replication.serverId}"}
       ${optionalString (cfg.ensureUsers != [])
       ''
@@ -319,6 +321,7 @@ in
                 mkdir -m 0700 -p ${cfg.dataDir}
                 chown -R ${cfg.user} ${cfg.dataDir}
                 ${mysql}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${installOptions}
+                ${optionalString (cfg.replication.role == "master" || cfg.replication.role == "slave") "rm ${cfg.dataDir}/mysql-bin-${toString cfg.replication.serverId}.*"}
                 touch /tmp/mysql_init
             fi

@flokli

This comment has been minimized.

Copy link
Contributor

flokli commented May 18, 2019

I also saw the log messages recommending to setup a relay-log, so this might be a good idea.

Not so sure about the rm ${cfg.dataDir}/mysql-bin-${toString cfg.replication.serverId}.* part - why would we want to remove the binary log from servers or slaves during initial setup?

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 18, 2019

mysql-bin log causes replication conflict, since perhaps they are identical (sorry, bad english)

@flokli

This comment has been minimized.

Copy link
Contributor

flokli commented May 18, 2019

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented May 18, 2019

Not running check mysqlReplication (
Create new PR with latest variant?

@flokli

This comment has been minimized.

Copy link
Contributor

flokli commented May 18, 2019

Let's continue discussion in #61671. Thanks!

@flokli flokli mentioned this pull request May 18, 2019
3 of 10 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.