Skip to content

Instantly share code, notes, and snippets.

@waja
Last active January 21, 2025 11:44

Revisions

  1. waja revised this gist Jul 20, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions create_debian-sys-maint_for_mysqladmin.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ MYSQLADMIN_CFG="/etc/mysql/mariadb.conf.d/90-mysqladmin.cnf"
    PASS=$(perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)');
    # adjust /etc/mysql/debian.cnf (used as defaults file by system scripts)
    sed -i "s/^password =.*$/password = ${PASS}/" /etc/mysql/debian.cnf
    sed -i "s/^user =.*$/user = debian-sys-maint/" /etc/mysql/debian.cnf
    # create config file for mysqladmin itself (maybe not needed)
    umask 066
    cat > ${MYSQLADMIN_CFG} <<EOF
  2. waja revised this gist Jul 20, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions create_debian-sys-maint_for_mysqladmin.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,9 @@
    MYSQLADMIN_CFG="/etc/mysql/mariadb.conf.d/90-mysqladmin.cnf"
    # generate password
    PASS=$(perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)');
    # create config file
    # adjust /etc/mysql/debian.cnf (used as defaults file by system scripts)
    sed -i "s/^password =.*$/password = ${PASS}/" /etc/mysql/debian.cnf
    # create config file for mysqladmin itself (maybe not needed)
    umask 066
    cat > ${MYSQLADMIN_CFG} <<EOF
    [mysqladmin]
    @@ -14,4 +16,4 @@ EOF
    umask 022
    chown 0:0 ${MYSQLADMIN_CFG}; chmod 0600 ${MYSQLADMIN_CFG}
    # update credentials
    mysql -u root -p -e "GRANT ALL ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${PASS}' WITH GRANT OPTION;"
    mysql -u root -p -e "GRANT ALL ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${PASS}' WITH GRANT OPTION;"
  3. waja created this gist Jul 20, 2017.
    17 changes: 17 additions & 0 deletions create_debian-sys-maint_for_mysqladmin.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/bin/sh
    MYSQLADMIN_CFG="/etc/mysql/mariadb.conf.d/90-mysqladmin.cnf"
    # generate password
    PASS=$(perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)');
    # create config file
    umask 066
    cat > ${MYSQLADMIN_CFG} <<EOF
    [mysqladmin]
    host = localhost
    user = debian-sys-maint
    password = ${PASS}
    socket = /var/run/mysqld/mysqld.sock
    EOF
    umask 022
    chown 0:0 ${MYSQLADMIN_CFG}; chmod 0600 ${MYSQLADMIN_CFG}
    # update credentials
    mysql -u root -p -e "GRANT ALL ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${PASS}' WITH GRANT OPTION;"