Discover Centmin Mod today
Register Now

[Solved] mysqladmin_shell.sh issue

Discussion in 'Bug Reports' started by Jimmy, Mar 24, 2018.

  1. Jimmy

    Jimmy Premium Member Premium Member

    1,350
    285
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +695
    Local Time:
    11:45 AM
    1.13.x
    MariaDB 10.1.x
    Please fill in any relevant information that applies to you:
    • CentOS Version: CentOS 7 64bit ?
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: latest
    • PHP Version Installed: 7.1.15
    • MariaDB MySQL Version Installed: 10.1.x
    • When was last time updated Centmin Mod code base ? : 67 years ago
    • Persistent Config: I went to the doctor and he cleared up my persistent config.
    Used mysqladmin_shell.sh to create a bunch of db / user / password.

    Code:
    dev_121_dbase dev_121_user mypass
    dev_122_dbase dev_122_user mypass
    dev_123_dbase dev_123_user mypass
    dev_124_dbase dev_124_user mypass
    dev_125_dbase dev_125_user mypass
    dev_126_dbase dev_126_user mypass
    dev_127_dbase dev_127_user mypass
    dev_128_dbase dev_128_user mypass
    dev_129_dbase dev_129_user mypass
    dev_130_dbase dev_130_user mypass
    dev_131_dbase dev_131_user mypass
    dev_132_dbase dev_132_user mypass
    dev_133_dbase dev_133_user mypass
    dev_134_dbase dev_134_user mypass
    dev_135_dbase dev_135_user mypass
    dev_136_dbase dev_136_user mypass
    dev_137_dbase dev_137_user mypass
    dev_138_dbase dev_138_user mypass
    dev_139_dbase dev_139_user mypass
    It created every database, only created the first 2 users (121 and 122).

    I deleted all databases except 121 and 122 and tried the script again (removing the 121 and 122 entries from the .txt file).
    Code:
    [[email protected] ~]# cd /usr/local/src/centminmod/addons/
    Code:
    [[email protected] addons]# ./mysqladmin_shell.sh multidb /root/dblist.txt
    --------------------------------------------------------------
    Basic MySQL Admin - create mysql user & databases 
    --------------------------------------------------------------
    --------------------------------------------------------------
    
    ----------------------------------------------------------------------------
    Create Multiple MySQL Databases, User & Pass From specified filepath/name
    i.e. /home/nginx/domains/domain.com/dbfile.txt
    One entry per line in dbfile.txt in format of:
    databasename databaseuser databasepass
    ----------------------------------------------------------------------------
    
    ---------------------------------
    Ok: MySQL user: dev_123_user MySQL database: dev_123_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_124_user MySQL database: dev_124_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_125_user MySQL database: dev_125_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_126_user MySQL database: dev_126_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_127_user MySQL database: dev_127_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_128_user MySQL database: dev_128_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_129_user MySQL database: dev_129_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_130_user MySQL database: dev_130_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_131_user MySQL database: dev_131_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_132_user MySQL database: dev_132_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_133_user MySQL database: dev_133_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_134_user MySQL database: dev_134_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_135_user MySQL database: dev_135_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_136_user MySQL database: dev_136_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_137_user MySQL database: dev_137_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_138_user MySQL database: dev_138_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev_139_user MySQL database: dev_139_dbase created successfully
    
    Here is the MYSQL info output after using the script.

    Code:
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | dev_120_dbase      |
    | dev_121_dbase      |
    | dev_123_dbase      |
    | dev_124_dbase      |
    | dev_125_dbase      |
    | dev_126_dbase      |
    | dev_127_dbase      |
    | dev_128_dbase      |
    | dev_129_dbase      |
    | dev_130_dbase      |
    | dev_131_dbase      |
    | dev_132_dbase      |
    | dev_133_dbase      |
    | dev_134_dbase      |
    | dev_135_dbase      |
    | dev_136_dbase      |
    | dev_137_dbase      |
    | dev_138_dbase      |
    | dev_139_dbase      |
    | information_schema |
    | mysql              |
    | performance_schema |
    | pgo_train          |
    +--------------------+
    23 rows in set (0.00 sec)
    Code:
    MariaDB [(none)]> SELECT User FROM mysql.user;
    +--------------+
    | User         |
    +--------------+
    | root         |
    | root         |
    | root         |
    | dev_120_user |
    | dev_121_user |
    | dev_123_user |
    | root         |
    +--------------+
    7 rows in set (0.00 sec)
     
  2. eva2000

    eva2000 Administrator Staff Member

    35,514
    7,833
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,072
    Local Time:
    1:45 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    haven't checked but most likely due to use of double underscores. Best practice is limit to one underscore and see i.e. dev123_dbbase and dev123_user

    dam time flew !
     
    • Like Like x 1
  3. eva2000

    eva2000 Administrator Staff Member

    35,514
    7,833
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,072
    Local Time:
    1:45 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    hmm seems single underscore also has issues! will check it out
     
    • Informative Informative x 1
  4. Jimmy

    Jimmy Premium Member Premium Member

    1,350
    285
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +695
    Local Time:
    11:45 AM
    1.13.x
    MariaDB 10.1.x
    Sounds good. Thought I'd be safe using the underscore, I guess I was wrong.
     
  5. eva2000

    eva2000 Administrator Staff Member

    35,514
    7,833
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,072
    Local Time:
    1:45 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    Looks like it's my code as it sees using same database user password as being the same mysql user so skips creating that user. If you use different database passwords it works
    Code (Text):
    cat /root/dblist.txt
    dev136_dbase dev136_user mypass136
    dev137_dbase dev137_user mypass137
    

    Code (Text):
    ./mysqladmin_shell.sh multidb /root/dblist.txt      
    --------------------------------------------------------------
    Basic MySQL Admin - create mysql user & databases
    --------------------------------------------------------------
    --------------------------------------------------------------
    
    ----------------------------------------------------------------------------
    Create Multiple MySQL Databases, User & Pass From specified filepath/name
    i.e. /home/nginx/domains/domain.com/dbfile.txt
    One entry per line in dbfile.txt in format of:
    databasename databaseuser databasepass
    ----------------------------------------------------------------------------
    
    ---------------------------------
    Ok: MySQL user: dev136_user MySQL database: dev136_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev137_user MySQL database: dev137_dbase created successfully
    

    Code (Text):
    mysql -e "select user from mysql.user;"                          
    +-------------+
    | user        |
    +-------------+
    | root        |
    | root        |
    | root        |
    | dev136_user |
    | dev137_user |
    | root        |
    +-------------+
    


    Portion code
    Code (Text):
            if [[ "$DBCHECK" = '0' ]]; then
                if [ -f /tmp/mysqladminshell_userpass.txt ]; then
                    PREV_USER=$(awk '{print $1}' /tmp/mysqladminshell_userpass.txt)
                    PREV_PASS=$(awk '{print $2}' /tmp/mysqladminshell_userpass.txt)
                fi
                if [[ "$PREV_USER" != "$u" && "$PREV_PASS" != "$p" ]]; then
                    # if PREV_USER not equal to $u AND PREV_PASS not equal to $p
                    # then it's not the same mysql username and pass so create the
                    # mysql username
                    mysql ${MYSQLOPTS} -e "CREATE USER '$u'@'$MYSQLHOSTNAME' IDENTIFIED BY '$p';" >/dev/null 2>&1
                    USERCHECK=$?
                elif [[ "$PREV_USER" = "$u" && "$PREV_PASS" = "$p" ]]; then
                    # if PREV_USER equal to $u AND PREV_PASS equal to $p
                    # then it's same mysql username and pass so skip
                    # mysql user creation
                    USERCHECK=0
                elif [[ -z "$u" && -z "$p" ]]; then
                    # if mysql username and password empty
                    # skip mysql user creation
                    USERCHECK=0
                fi
            else
                cecho "Error: unable to create DATABASE = $db" $boldgreen
                USERCHECK=1
            fi
    

    will need to see what can be done to fix this
     
    • Informative Informative x 1
  6. Jimmy

    Jimmy Premium Member Premium Member

    1,350
    285
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +695
    Local Time:
    11:45 AM
    1.13.x
    MariaDB 10.1.x
    I can use different passwords. Good to know it's only that.
     
  7. eva2000

    eva2000 Administrator Staff Member

    35,514
    7,833
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,072
    Local Time:
    1:45 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    yeah the current routine was setup that way so that if user populates dblist.txt with same username/password for multiple databases, the script will skip creating the db user/password as it already exists but it seems to not differentiate the db user which maybe due to underscore ? Will have to check
     
    • Informative Informative x 1
  8. eva2000

    eva2000 Administrator Staff Member

    35,514
    7,833
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,072
    Local Time:
    1:45 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    FYI just updated 123.09beta01 with fix so run cmupdate command or centmin.sh menu option 23 submenu option 2 to update locate server code for 123.09beta01
    Code (Text):
    cat /root/dblist.txt
    dev256_dbase dev256_user mypass
    dev257_dbase dev257_user mypass
    

    Code (Text):
    ./mysqladmin_shell.sh multidb /root/dblist.txt       
    --------------------------------------------------------------
    Basic MySQL Admin - create mysql user & databases
    --------------------------------------------------------------
    --------------------------------------------------------------
    
    ----------------------------------------------------------------------------
    Create Multiple MySQL Databases, User & Pass From specified filepath/name
    i.e. /home/nginx/domains/domain.com/dbfile.txt
    One entry per line in dbfile.txt in format of:
    databasename databaseuser databasepass
    ----------------------------------------------------------------------------
    
    ---------------------------------
    Ok: MySQL user: dev256_user MySQL database: dev256_dbase created successfully
    
    
    ---------------------------------
    Ok: MySQL user: dev257_user MySQL database: dev257_dbase created successfully
    

    Code (Text):
    mysql -e "select user from mysql.user;"               
    +-------------+
    | user        |
    +-------------+
    | root        |
    | root        |
    | root        |
    | dev256_user |
    | dev257_user |
    | root        |
    +-------------+
    
     
    • Winner Winner x 2
  9. Jimmy

    Jimmy Premium Member Premium Member

    1,350
    285
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +695
    Local Time:
    11:45 AM
    1.13.x
    MariaDB 10.1.x
    Thanks!
     
..