Want to subscribe to topics you're interested in?
Become a Member

mysqladmin_shell.sh Shell based Addon

Discussion in 'Add Ons' started by eva2000, Jun 23, 2014.

  1. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    10:29 PM
    nginx/1.11.4
    MariaDB 10
    Sorry, @eva2000 it was my mistake, I run it from tools directory, when I run from addons directories it works.

    worked.png
     
  2. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    yes has to be run from addons/ directory :)
     
  3. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    10:29 PM
    nginx/1.11.4
    MariaDB 10
    Many thanks @eva2000, hope you can make a simple command like this if we want to add many domain, so we can easily to remember it. I mean not like below command.;)

    Code:
    while read -r d s f; do echo "nv -d $d -s $s -u $f"; nv -d $d -s $s -u $f; done < /home/vhostlist.txt
     
  4. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    ah but excercising your memory is good for you :D
     
  5. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    10:29 PM
    nginx/1.11.4
    MariaDB 10
    hahaha.. forget it :hungover:
     
  6. RB1

    RB1 Active Member

    285
    75
    28
    Nov 11, 2016
    California
    Ratings:
    +122
    Local Time:
    8:29 AM
    Nginx 1.18.x
    MariaDB 10.1.x
    What about ./mysqladmin_shell.sh deldb

    :)
     
  7. hendry

    hendry Member

    59
    14
    8
    Sep 19, 2016
    Ratings:
    +18
    Local Time:
    10:29 PM
    nginx/1.11.4
    MariaDB 10
    You can use this simple command without entering your mysql or phpmyadmin:

    Code (Text):
    mysql -e "DROP DATABASE dbname;"
     
  8. RB1

    RB1 Active Member

    285
    75
    28
    Nov 11, 2016
    California
    Ratings:
    +122
    Local Time:
    8:29 AM
    Nginx 1.18.x
    MariaDB 10.1.x
    I know :)
     
  9. pamamolf

    pamamolf Premium Member Premium Member

    3,858
    379
    83
    May 31, 2014
    Ratings:
    +731
    Local Time:
    5:29 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    It will be good to have some remove/delete users option and for database empty/delete options also from mysqladmin tool :)

    For example if i want to recover a database i do not have to delete my existing database and re create it as i can just empty it by deleting all tables of it :)
     
  10. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    yes deletion and other user removal choices are to come :)
     
  11. pamamolf

    pamamolf Premium Member Premium Member

    3,858
    379
    83
    May 31, 2014
    Ratings:
    +731
    Local Time:
    5:29 PM
    Nginx-1.17.x
    MariaDB 10.3.x
    What about a menu so we will not have to remember all parameters of it?
     
  12. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    just type mysqladmin_shell.sh without parameters should give you help output with such :)
     
  13. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x

    mysqladmin_shell.sh createuserdb Added



    New mysqladmin_shell.sh option has been added for createuserdb option. This allows unattended creating of a mysql database + mysql username + mysql password without any question prompts. Suited for scripted setups where you want to create mysql database, user and password on the command line.

    Full addons/mysqladmin_shell.sh options

    Code (Text):
    ./mysqladmin_shell.sh
    
    ./mysqladmin_shell.sh {multidb|setglobaluser|setuserdb|setpass|createuserdb|deluser|showgrants}
    
    multidb - multiple mysql databse/user creation mode passing a file name containing db, user, pass 3 column entries
    setglobaluser - create a mysql username with access to all databases on server without SUPER ADMIN privileges (non-root)
    setuserdb - create individual mysql username and databases or assign a new database to an existing mysql username
    setpass - change mysql username password
    createuserdb - unattended create individual mysql username & databases fields required are dbname dbuser dbpass
    deluser - delete a mysql usernames
    showgrants - show existing mysql username granted privileges
    

    Example for createuserdb run where you pass on command line the database name, mysql username and mysql password - in this example db name = xdb1, db user = xdbuser1 and db pass = xdbpass1
    Code (Text):
    ./mysqladmin_shell.sh createuserdb xdb1 xdbuser1 xdbpass1
    --------------------------------------------------------------
    Basic MySQL Admin - create mysql user & databases
    --------------------------------------------------------------
    --------------------------------------------------------------
    
    Grants for xdb1@localhost
    GRANT USAGE ON *.* TO 'xdb1'@'localhost' IDENTIFIED BY PASSWORD '*6D7525873C093916CA45CF6A9F12142EFC4C5F38'
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `createuserdb`.* TO 'xdb1'@'localhost'
    
    Ok: MySQL user: xdb1 MySQL database: createuserdb created successfully
    

    This is opposed to using the old setuserdb command which creates the mysql database name, db user and db pass with question prompts interactively below example created mysql dbname = ydb1, db user = ydbuser1 and db pass = ydbpass1
    Code (Text):
    ./mysqladmin_shell.sh setuserdb
    --------------------------------------------------------------
    Basic MySQL Admin - create mysql user & databases
    --------------------------------------------------------------
    --------------------------------------------------------------
    
     Do you want to create a new MySQL username (type = y) or
     Add a new database name to existing MySQL username (type = n) ?
     Enter y or n: y
    ---------------------------------
    Create MySQL username:
    ---------------------------------
     Enter new MySQL username you want to create: ydbuser1
     Enter new MySQL username's password: ydbpass1
    ---------------------------------
    Create MySQL database:
    ---------------------------------
     Enter new MySQL database name: ydb1
    
    Grants for ydbuser1@localhost
    GRANT USAGE ON *.* TO 'ydbuser1'@'localhost' IDENTIFIED BY PASSWORD '*34CE4FFBB62702263F1970A79FB0BA6CF651489B'
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON `ydb1`.* TO 'ydbuser1'@'localhost'
    
    Ok: MySQL user: ydbuser1 MySQL database: ydb1 created successfully
    
     
    Last edited: May 8, 2017
  14. Jimmy

    Jimmy Well-Known Member

    1,706
    365
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +923
    Local Time:
    11:29 AM
    1.17.x
    MariaDB 10.3.x
    This is a wonderful addition to CMM. Just started using it.
     
  15. Jimmy

    Jimmy Well-Known Member

    1,706
    365
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +923
    Local Time:
    11:29 AM
    1.17.x
    MariaDB 10.3.x
    If using multidb with a database file with special characters in the password, do the passwords need to be in single quotes? Or can we omit the single quotes?

    Code:
    dbm1 dbmuser1 'dbmpa$$1'
    dbm2 dbmuser2 'dbmpa$$2'
     
  16. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    omit the single quotes
     
  17. Jimmy

    Jimmy Well-Known Member

    1,706
    365
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +923
    Local Time:
    11:29 AM
    1.17.x
    MariaDB 10.3.x
    Without single quotes:
    Code:
    -bash: !,UEzeJH8c[: event not found
    Doesn't work with single quotes either.
     
  18. Jimmy

    Jimmy Well-Known Member

    1,706
    365
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +923
    Local Time:
    11:29 AM
    1.17.x
    MariaDB 10.3.x
    Using this:
    Code:
    ./mysqladmin_shell.sh createuserdb art7er33u29wwe art3u7qu 'wT`YuFTp?eN)o>3QR~!,UEzeJH8c[:g:h@D9Hq6f2(^KMwA(p"%EH.GJMeUw&NHFc#K"T*F-&}F'
    It created a database called, createuserdb.
    Code:
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | createuserdb       |
    | information_schema |
    | mysql              |
    | performance_schema |
    | pgo_train          |
    +--------------------+
    
     
  19. eva2000

    eva2000 Administrator Staff Member

    45,441
    10,313
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,995
    Local Time:
    1:29 AM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Yeah you single quote and back ticks are causing problems for password in ssh I'd use less special characters that have single quotes,questions marks, back ticks, dollars signs, asterisk, curly braces, square brackets as they have special meaning for shell
     
  20. Jimmy

    Jimmy Well-Known Member

    1,706
    365
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +923
    Local Time:
    11:29 AM
    1.17.x
    MariaDB 10.3.x
    I figured as much. I'll use less characters. :)