create_debian-sys-maint_for_mysqladmin.sh
· 818 B · Bash
Raw
#!/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)');
# 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
[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;"
| 1 | #!/bin/sh |
| 2 | MYSQLADMIN_CFG="/etc/mysql/mariadb.conf.d/90-mysqladmin.cnf" |
| 3 | # generate password |
| 4 | PASS=$(perl -e 'print map{("a".."z","A".."Z",0..9)[int(rand(62))]}(1..16)'); |
| 5 | # adjust /etc/mysql/debian.cnf (used as defaults file by system scripts) |
| 6 | sed -i "s/^password =.*$/password = ${PASS}/" /etc/mysql/debian.cnf |
| 7 | sed -i "s/^user =.*$/user = debian-sys-maint/" /etc/mysql/debian.cnf |
| 8 | # create config file for mysqladmin itself (maybe not needed) |
| 9 | umask 066 |
| 10 | cat > ${MYSQLADMIN_CFG} <<EOF |
| 11 | [mysqladmin] |
| 12 | host = localhost |
| 13 | user = debian-sys-maint |
| 14 | password = ${PASS} |
| 15 | socket = /var/run/mysqld/mysqld.sock |
| 16 | EOF |
| 17 | umask 022 |
| 18 | chown 0:0 ${MYSQLADMIN_CFG}; chmod 0600 ${MYSQLADMIN_CFG} |
| 19 | # update credentials |
| 20 | mysql -u root -p -e "GRANT ALL ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '${PASS}' WITH GRANT OPTION;" |
| 21 |