Skip to content

Instantly share code, notes, and snippets.

@waja
Last active April 18, 2022 18:57
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save waja/da28a83b29cd67ad01f4d9880c341ff0 to your computer and use it in GitHub Desktop.
Save waja/da28a83b29cd67ad01f4d9880c341ff0 to your computer and use it in GitHub Desktop.
Create 'debian-sys-maint' MariaDB user for use of mysqladmin. Just in case you can't use 'root' via 'unix_socket' plugin.
#!/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;"
@C0rn3j
Copy link

C0rn3j commented Dec 3, 2020

Just in case someone lands here - the debian-sys-maint account is not used since 10.4 due to unix sockets, as hinted in this gist's description.

https://mariadb.org/authentication-in-mariadb-10-4/

@waja
Copy link
Author

waja commented Dec 3, 2020

Just in case someone lands here - the debian-sys-maint account is not used since 10.4 due to unix sockets, as hinted in this gist's description.

And for this reason, this script is recreating the old behaviour.

@jpptinsley
Copy link

Google landed me here, useful thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment