The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Database user not being associated with database

Discussion in 'Database Discussions' started by Sindre, Jan 31, 2014.

  1. Sindre

    Sindre Well-Known Member

    Joined:
    Aug 25, 2008
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    I have created a bash script to automate some tasks. Part of the script creates a new database and user for a cPanel user. I have the following code:

    Code:
    # Create database and grants
    
    ESCAPED_DB_NAME=${db_name/_/\\_}
    Q1="CREATE DATABASE IF NOT EXISTS \`${db_name}\`;"
    Q2="GRANT ALL PRIVILEGES ON \`${ESCAPED_DB_NAME}\`.* TO '${db_user}'@'localhost' IDENTIFIED BY '${db_pass}';"
    Q3="FLUSH PRIVILEGES;"
    SQL="${Q1}${Q2}${Q3}"
    
    mysql -e "$SQL"
    
    # Map new DB to cPanel user
    /usr/local/cpanel/bin/dbmaptool $user --type mysql --dbs "${db_name}" --dbusers "${db_user}"
    
    Everything works as expected, except when I look at the MySQL Databases section the user is not associated with the database. Both the user and database shows up, but the Users column for the database is empty.

    None of the following commands have any effect

    Code:
    /usr/local/cpanel/bin/dbstoregrants username (this does update the /var/cpanel/databases/grants_username.yaml file correctly)
    /usr/local/cpanel/bin/dbindex
    /usr/local/cpanel/bin/setupdbmap
    
    What am I missing here? Is there some command to make sure the grants show up in cPanel?

    As I said, everything works fine with the SQL. Database and user is created correctly, and the user has access to the database, but it does not show up correctly in cPanel.

    Any advise will be appreciate.

    Thank you,
    Sindre
     
    #1 Sindre, Jan 31, 2014
    Last edited: Jan 31, 2014
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    653
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
  3. Sindre

    Sindre Well-Known Member

    Joined:
    Aug 25, 2008
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    Thanks. Ticket has been created: 4516311
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    653
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    To update, it was determined that the issue could not be reproduced on a standard MySQL installation with cPanel. The server in question was using Percona, which possibly contributed to the issue. The user was able to implement a solution through the edit of the /var/cpanel/databases/$user.cache and /var/cpanel/databases/$user.yaml files.

    Thank you.
     
Loading...

Share This Page