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.

Create new database with UAPI functions.

Discussion in 'Database Discussions' started by Zubair Moolla, Feb 19, 2017.

Tags:
  1. Zubair Moolla

    Zubair Moolla Registered

    Joined:
    Feb 19, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Auckland
    cPanel Access Level:
    Root Administrator
    Hi,

    I am trying to create a MySQL database and set a current database user to the database.

    The PHP code is written as below;

    $site = "http://[cpanel_user]:[cpanel_password]@localhost:2082/execute/Mysql/";

    $result = file_get_contents("{$site}create_database?name=zubair_test");
    $result .= file_get_contents("{$site}set_privileges_on_database?user=zubair_admin&database=zubair_test&privileges=ALL%20PRIVILEGES");

    print $result;

    Now the database is being created fine with no errors, and it is mapped to the correct CPANEL user.

    The issue I am having is setting a current database user to the newly created database. I am receiving the following error response.

    {"errors":["(XID kamdnm) Database Error: There is no such grant defined for user 'zubair_admin' on host 'localhost'"],"status":0,"data":null,"messages":null,"metadata":{}}

    Am I handling this the correct way to add a user to the newly created database? Perhaps could be a permissions issue with the current connection to MySQL? (The database user 'zubair_admin' I am trying to set to the database is the user I am connecting with).

    Any advice or solutions will be much appreciated.

    Thanks,
    Zubair.
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you verify which version of cPanel is installed on this system? EX:

    Code:
    cat /usr/local/cpanel/version
    Thank you.
     
  3. Zubair Moolla

    Zubair Moolla Registered

    Joined:
    Feb 19, 2017
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Auckland
    cPanel Access Level:
    Root Administrator
    Hi,

    The version installed is 11.62.0.15

    Thanks,
    Zubair
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,287
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you verify how you are adding the database user? Can you reproduce the issue with newly created database users?

    The following document is helpful if you have made direct changes to a MySQL user's grants in the past:

    The dbstoregrants Script - Documentation - cPanel Documentation

    Thank you.
     
Loading...

Share This Page