mysql-entrypoint.sh 603 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

set -euo pipefail

init_datadir() {
    mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

    mysqld_safe --datadir=/var/lib/mysql &
    until : > /dev/tcp/127.0.0.1/3306; do
        sleep 1s
    done

    mysql -u root <<'    EOSQL'
        CREATE USER 'aur'@'%' IDENTIFIED BY 'aur';
        CREATE DATABASE aurweb;
        GRANT ALL PRIVILEGES ON aurweb.* TO 'aur'@'%';
        FLUSH PRIVILEGES;
    EOSQL

    mysqladmin -uroot shutdown
}

# Only initialize the datadir if it's uninitialized.
if ! test -d /var/lib/mysql/mysql; then
    init_datadir
fi

exec "$@"