mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-26 04:29:25 -05:00
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.
This commit is contained in:
parent
3323ffa66d
commit
351bada950
1 changed files with 18 additions and 39 deletions
|
@ -30,6 +30,7 @@ (define-module (gnu services databases)
|
||||||
#:use-module (gnu services shepherd)
|
#:use-module (gnu services shepherd)
|
||||||
#:use-module (gnu system shadow)
|
#:use-module (gnu system shadow)
|
||||||
#:use-module (gnu packages admin)
|
#:use-module (gnu packages admin)
|
||||||
|
#:use-module (gnu packages base)
|
||||||
#:use-module (gnu packages databases)
|
#:use-module (gnu packages databases)
|
||||||
#:use-module (guix build-system trivial)
|
#:use-module (guix build-system trivial)
|
||||||
#:use-module (guix build union)
|
#:use-module (guix build union)
|
||||||
|
@ -612,44 +613,21 @@ (define (mysql-install config)
|
||||||
(with-imported-modules (source-module-closure
|
(with-imported-modules (source-module-closure
|
||||||
'((guix build utils)))
|
'((guix build utils)))
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (ice-9 popen)
|
(use-modules (guix build utils))
|
||||||
(guix build utils))
|
;; Make sed, mkdir, uname, etc available for mariadb-install-db.
|
||||||
(let ((mysqld (string-append #$mysql "/bin/mysqld")))
|
(set-path-environment-variable "PATH" '("bin")
|
||||||
(if (string-prefix? "mysql-" (strip-store-file-name #$mysql))
|
(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.
|
;; For MySQL.
|
||||||
(system* mysqld
|
(system* #$(file-append mysql "/bin/mysqld")
|
||||||
(string-append "--defaults-file=" #$my.cnf)
|
(string-append "--defaults-file=" #$my.cnf)
|
||||||
"--initialize"
|
"--initialize"
|
||||||
"--user=mysql")
|
"--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)))))))))
|
|
||||||
|
|
||||||
(define (mysql-upgrade-wrapper config)
|
(define (mysql-upgrade-wrapper config)
|
||||||
;; The MySQL socket and PID file may appear before the server is ready to
|
;; The MySQL socket and PID file may appear before the server is ready to
|
||||||
|
@ -672,7 +650,8 @@ (define (mysql-upgrade-wrapper config)
|
||||||
(close-port sock)
|
(close-port sock)
|
||||||
;; The socket is ready!
|
;; The socket is ready!
|
||||||
(execl mysql-upgrade mysql-upgrade
|
(execl mysql-upgrade mysql-upgrade
|
||||||
(string-append "--defaults-file=" #$config-file))))
|
(string-append "--defaults-file=" #$config-file)
|
||||||
|
"--user=mysql")))
|
||||||
(lambda args
|
(lambda args
|
||||||
(if (< i timeout)
|
(if (< i timeout)
|
||||||
(begin
|
(begin
|
||||||
|
|
Loading…
Reference in a new issue