aboutsummaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorMarius Bakke <marius@gnu.org>2022-10-29 22:39:50 +0200
committerMarius Bakke <marius@gnu.org>2022-11-20 17:54:05 +0100
commit351bada95049f0023aaf2fc7c91ee4b33e94486c (patch)
tree8043bd47cd70da0332890d9526dc2ad7bb786dba /gnu/services
parent3323ffa66d6edfadad312fad15f91a02d3262174 (diff)
downloadguix-351bada95049f0023aaf2fc7c91ee4b33e94486c.tar
guix-351bada95049f0023aaf2fc7c91ee4b33e94486c.tar.gz
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.
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/databases.scm57
1 files 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