Last active
September 5, 2018 18:06
-
-
Save wilxsv/0c6a7dc31cf46c661f414aae3b54fc8d to your computer and use it in GitHub Desktop.
script para creacion de bases de datos para las alumnas y alumnos de comercio electronico
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
#Script recibe dos parametros, 1 el carnet del estudiante, 2 el password | |
UUID=$(cat /proc/sys/kernel/random/uuid) | |
#Creo el usuario | |
BASE0=$(mysql -u root -ppasswd -D mysql -e "CREATE USER $1@localhost IDENTIFIED BY '$2'; " 2> /tmp/$UUID.txt) | |
#Le doy permisos de consulta | |
BASE1=$(mysql -u root -D mysql -ppasswd -e "GRANT USAGE ON *.* TO $1@localhost IDENTIFIED BY '$2' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;" 2>> /tmp/$UUID.txt) | |
#Creo la base | |
BASE2=$(mysql -u root -D mysql -ppasswd -e "CREATE DATABASE IF NOT EXISTS $1;" 2>> /tmp/$UUID.txt) | |
#Le doy permiso solo a esa base | |
BASE3=$(mysql -u root -D mysql -ppasswd -e "GRANT ALL PRIVILEGES ON $1.* TO $1@localhost" 2>> /tmp/$UUID.txt) | |
echo -e "Hola $1"; | |
echo -e "mysql te manda a decir que : "; | |
echo $BASE0 | |
echo $BASE1 | |
echo $BASE2 | |
echo $BASE3 | |
echo -e "Si no dijo nada tu base se creo y puedes verificar con el comando\n\tmysql -u $1 -D $1 -p \nO revisa el archivo /tmp/$UUID.txt"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment