# generar password para mysql password=$( apg -M CLN -m 30 -n 1 ) echo "El password para mysql será: $password" # instalación segura de MariaDB mysql -u root << EOF # agregar password a usuario root UPDATE mysql.user SET Password = PASSWORD( '${password}' ) WHERE User = 'root'; # eliminar acceso a usuario root sin password DELETE FROM mysql.user WHERE User = ''; DELETE FROM mysql.user WHERE User = 'root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); # remover db de pruebas DROP DATABASE IF EXISTS test; DELETE FROM mysql.db WHERE Db = 'test' OR Db = 'test\\_%'; # re-cargar privilegios FLUSH PRIVILEGES; EOF # crear archivo .my.cnf cat << EOF > /root/.my.cnf [client] user = root password = $password host = localhost EOF # crear usuario y contraseña para base de datos user=$( apg -M CLN -m 15 -n 1 ) password=$( apg -M CLN -m 30 -n 1 ) cat << EOF Base de datos Usuario: $user Password: $password EOF # crear base de datos mysql -e 'CREATE DATABASE `mst_tld-site` DEFAULT CHARSET utf8;' mysql -e "CREATE USER '$user'@'localhost' IDENTIFIED BY '$password';" mysql -e "GRANT ALL PRIVILEGES ON \`mst_tld-site\`.* TO '$user'@'localhost';"