Skip to content

Instantly share code, notes, and snippets.

@nateflink
Last active November 10, 2024 05:08
Show Gist options
  • Save nateflink/5785237 to your computer and use it in GitHub Desktop.
Save nateflink/5785237 to your computer and use it in GitHub Desktop.

Revisions

  1. nateflink revised this gist Jun 16, 2013. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,8 @@
    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "ERROR Usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    exit
    echo "Usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    exit 1
    fi

    DB_PASSWORD=$(env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 16)
    @@ -26,4 +26,5 @@ EOF
    )

    mysql -u "$1" -p"$2" -e "$CMD"
    echo "$DB_PASSWORD"
    echo "$DB_PASSWORD"
    exit 0
  2. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "ERROR Usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    echo "ERROR Usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    exit
    fi

  3. nateflink revised this gist Jun 16, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    #!/bin/bash
    # By N Flink
    #By Nate Flink

    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    echo "ERROR Usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    exit
    fi

  4. nateflink revised this gist Jun 16, 2013. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,5 @@
    #!/bin/bash
    # __ __ ______ __ __ __ __ __ __
    # /\ "-.\ \ /\ ___\ /\ \ /\ \ /\ "-.\ \ /\ \/ /
    # \ \ \-. \ \ \ __\ \ \ \____ \ \ \ \ \ \-. \ \ \ _"-.
    # \ \_\\"\_\ \ \_\ \ \_____\ \ \_\ \ \_\\"\_\ \ \_\ \_\
    # \/_/ \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/
    # By N Flink

    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

  5. nateflink revised this gist Jun 16, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@
    # \ \_\\"\_\ \ \_\ \ \_____\ \ \_\ \ \_\\"\_\ \ \_\ \_\
    # \/_/ \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/


    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
  6. nateflink revised this gist Jun 16, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    #!/bin/bash


    # __ __ ______ __ __ __ __ __ __
    # /\ "-.\ \ /\ ___\ /\ \ /\ \ /\ "-.\ \ /\ \/ /
    # \ \ \-. \ \ \ __\ \ \ \____ \ \ \ \ \ \-. \ \ \ _"-.
  7. nateflink revised this gist Jun 16, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,6 @@
    # \/_/ \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/




    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
  8. nateflink revised this gist Jun 16, 2013. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,15 @@
    #!/bin/bash


    # __ __ ______ __ __ __ __ __ __
    # /\ "-.\ \ /\ ___\ /\ \ /\ \ /\ "-.\ \ /\ \/ /
    # \ \ \-. \ \ \ __\ \ \ \____ \ \ \ \ \ \-. \ \ \ _"-.
    # \ \_\\"\_\ \ \_\ \ \_____\ \ \_\ \ \_\\"\_\ \ \_\ \_\
    # \/_/ \/_/ \/_/ \/_____/ \/_/ \/_/ \/_/ \/_/\/_/




    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
  9. nateflink revised this gist Jun 14, 2013. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,19 @@
    #!/bin/bash

    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password
    # usage:


    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "usage: ./$0 [mysql db username] [mysql user password] [new identifier]"
    echo "usage: ./$0 [mysql db username] [mysql user password] [new identifier] [optional password]"
    exit
    fi

    DB_PASSWORD=$(env LC_CTYPE=C tr -dc "a-zA-Z0-9-_\$\?" < /dev/urandom | head -c 16)
    DB_USER=$3
    DB_PASSWORD=</dev/urandom LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\%\^\&\*\(\)-+ | head -c 24

    if [ -n "$4" ]; then
    DB_PASSWORD=$4
    fi


    #sql for creating a user and a database
    CMD=$(cat <<EOF
    @@ -20,7 +23,6 @@ CREATE DATABASE IF NOT EXISTS \`$DB_USER\`;
    GRANT ALL PRIVILEGES ON \`$DB_USER\` . * TO '$DB_USER'@'%';
    EOF
    )
    #echo "$CMD" > "$TMP_FILE"

    mysql -u "$1" -p"$2" -e "$CMD"
    echo "$DB_PASSWORD"
  10. nateflink revised this gist Jun 14, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@

    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "usage: ./$0 [mysql db username] [mysql user password] [new identifier]"
    exit
    fi

    DB_USER=$3
  11. nateflink created this gist Jun 14, 2013.
    25 changes: 25 additions & 0 deletions addmysqluser.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    # Adds a mysql user, and creates a database with the same name as the user and echos the generated password
    # usage:


    if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
    echo "usage: ./$0 [mysql db username] [mysql user password] [new identifier]"
    fi

    DB_USER=$3
    DB_PASSWORD=</dev/urandom LC_CTYPE=C tr -dc A-Za-z0-9_\!\@\#\%\^\&\*\(\)-+ | head -c 24

    #sql for creating a user and a database
    CMD=$(cat <<EOF
    CREATE USER '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD';
    GRANT USAGE ON * . * TO '$DB_USER'@'%' IDENTIFIED BY '$DB_PASSWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
    CREATE DATABASE IF NOT EXISTS \`$DB_USER\`;
    GRANT ALL PRIVILEGES ON \`$DB_USER\` . * TO '$DB_USER'@'%';
    EOF
    )
    #echo "$CMD" > "$TMP_FILE"

    mysql -u "$1" -p"$2" -e "$CMD"
    echo "$DB_PASSWORD"