[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
10/10: services: mysql: Run mariadb-install-db instead of hard coding sc
From: |
guix-commits |
Subject: |
10/10: services: mysql: Run mariadb-install-db instead of hard coding schemas. |
Date: |
Sun, 20 Nov 2022 11:56:26 -0500 (EST) |
mbakke pushed a commit to branch master
in repository guix.
commit 351bada95049f0023aaf2fc7c91ee4b33e94486c
Author: Marius Bakke <marius@gnu.org>
AuthorDate: Sat Oct 29 22:39:50 2022 +0200
services: mysql: Run mariadb-install-db instead of hard coding schemas.
* gnu/services/databases.scm (mysql-install): Run "mariadb-install-db"
instead
of a hard coded set of SQL commands.
(mysql-upgrade-wrapper): Explicitly run as mysql user.
---
gnu/services/databases.scm | 57 +++++++++++++++-------------------------------
1 file changed, 18 insertions(+), 39 deletions(-)
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 6f0e323c84..b7bd1e587e 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -30,6 +30,7 @@
#:use-module (gnu services shepherd)
#:use-module (gnu system shadow)
#:use-module (gnu packages admin)
+ #:use-module (gnu packages base)
#:use-module (gnu packages databases)
#:use-module (guix build-system trivial)
#:use-module (guix build union)
@@ -612,44 +613,21 @@ port=" (number->string port) "
(with-imported-modules (source-module-closure
'((guix build utils)))
#~(begin
- (use-modules (ice-9 popen)
- (guix build utils))
- (let ((mysqld (string-append #$mysql "/bin/mysqld")))
- (if (string-prefix? "mysql-" (strip-store-file-name #$mysql))
- ;; For MySQL.
- (system* mysqld
- (string-append "--defaults-file=" #$my.cnf)
- "--initialize"
- "--user=mysql")
- ;; For MariaDB.
- ;; XXX: The 'mysql_install_db' script doesn't work directly
- ;; due to missing 'mkdir' in PATH.
- (let ((p (open-pipe* OPEN_WRITE mysqld
- (string-append
- "--defaults-file=" #$my.cnf)
- "--bootstrap"
- "--user=mysql")))
- ;; Create the system database, as does by
'mysql_install_db'.
- (display "create database mysql;\n" p)
- (display "use mysql;\n" p)
- (for-each
- (lambda (sql)
- (call-with-input-file
- (string-append #$mysql:lib "/share/mysql/" sql)
- (lambda (in) (dump-port in p))))
- '("mysql_system_tables.sql"
- "mysql_performance_tables.sql"
- "mysql_system_tables_data.sql"
- "fill_help_tables.sql"))
- ;; Remove the anonymous user and disable root access from
- ;; remote machines, as does by 'mysql_secure_installation'.
- (display "
-DELETE FROM user WHERE User='';
-DELETE FROM user WHERE User='root' AND
- Host NOT IN ('localhost', '127.0.0.1', '::1');
-FLUSH PRIVILEGES;
-" p)
- (close-pipe p)))))))))
+ (use-modules (guix build utils))
+ ;; Make sed, mkdir, uname, etc available for mariadb-install-db.
+ (set-path-environment-variable "PATH" '("bin")
+ (list #$sed #$coreutils))
+ (if (string=? "mariadb" #$(package-name mysql))
+ ;; For MariaDB.
+ (system* #$(file-append mysql "/bin/mariadb-install-db")
+ (string-append "--defaults-file=" #$my.cnf)
+ "--skip-test-db"
+ "--user=mysql")
+ ;; For MySQL.
+ (system* #$(file-append mysql "/bin/mysqld")
+ (string-append "--defaults-file=" #$my.cnf)
+ "--initialize"
+ "--user=mysql")))))))
(define (mysql-upgrade-wrapper config)
;; The MySQL socket and PID file may appear before the server is ready to
@@ -672,7 +650,8 @@ FLUSH PRIVILEGES;
(close-port sock)
;; The socket is ready!
(execl mysql-upgrade mysql-upgrade
- (string-append "--defaults-file=" #$config-file))))
+ (string-append "--defaults-file=" #$config-file)
+ "--user=mysql")))
(lambda args
(if (< i timeout)
(begin
- branch master updated (da6c6763fa -> 351bada950), guix-commits, 2022/11/20
- 01/10: gnu: postgresql: Add 15.1., guix-commits, 2022/11/20
- 03/10: gnu: postgresql@11: Update to 11.18., guix-commits, 2022/11/20
- 02/10: gnu: postgresql@13: Update to 13.9., guix-commits, 2022/11/20
- 05/10: tests: mysql: Wait for the socket before running queries., guix-commits, 2022/11/20
- 06/10: gnu: mysql: Support custom data dir., guix-commits, 2022/11/20
- 07/10: services: mysql-upgrade: Support custom datadir., guix-commits, 2022/11/20
- 04/10: gnu: postgresql@10: Update to 10.23., guix-commits, 2022/11/20
- 08/10: services: mysql-upgrade: Add log file., guix-commits, 2022/11/20
- 09/10: services: mysql: Remove mysql-install-service in favor of wrapper., guix-commits, 2022/11/20
- 10/10: services: mysql: Run mariadb-install-db instead of hard coding schemas.,
guix-commits <=