Elevate account's MySQL user

bloom360

Active Member
Feb 23, 2015
28
4
3
cPanel Access Level
Root Administrator
Hi,

I am building an app on top of this: The multi tenant saas toolkit for Laravel

It needs a MySQL user with permission to create databases (all will remain under the same account)

I obviously know how to grant permissions via the GUI for an existing user to an existing database but, how can I elevate a user so that it can programatically create databases?

I tried making the account a reseller but it didn't appear to do the trick.

Many thanks!
 
Last edited by a moderator:
  • Like
Reactions: kadrin

kadrin

Active Member
Nov 13, 2019
34
6
8
Italy
cPanel Access Level
Website Owner
PHP code to create a MYSQL database
Code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Creating a connection
$conn = new mysqli($servername, $username, $password);
// Check mysql connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
// Creating a database named newDB
$sql = "CREATE DATABASE newDB";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";
} else {
    echo "Error creating db: " . $conn->error;
}

// closing connection
$conn->close();
?>
 

bloom360

Active Member
Feb 23, 2015
28
4
3
cPanel Access Level
Root Administrator
Thanks @kadrin but I still need to know how to elevate a MySQL user.

I am using an existing Laravel app which already takes care of creating the databases, I am not going to code it (and don't want to hack the codebase)
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,255
313
Houston
I obviously know how to grant permissions via the GUI for an existing user to an existing database but, how can I elevate a user so that it can programatically create databases?
You'd have to use the cPanel user account, using the API would be the best bet https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Mysql::create_database

 
  • Like
Reactions: kadrin

bloom360

Active Member
Feb 23, 2015
28
4
3
cPanel Access Level
Root Administrator
Thanks @cPanelLauren

However, I am using an existing app. I don't want to rebuild it. I appreciate the suggestions for alternatives but I really really need to know how to escalate a MySQL user, not workarounds please.
 

cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,295
1,255
313
Houston
That's not the issue, the problem is that it can't be done on a cPanel user level like you're requesting. I've already explained that. The only user that can access all databases despite ownership or that can access un-owned databases is the root MySQL user. The cPanel user can create new users but you must use the API calls to do this and have it recognized by cPanel.
 

bloom360

Active Member
Feb 23, 2015
28
4
3
cPanel Access Level
Root Administrator
Notice I do NOT need to create databases or users outside of the account. I only need to keep creating them within the account, just like the cPanel user would do through the API. Is this not possible at all by elevating MySQL permissions? I tried making the account a reseller, surely there must be a way methinks?
 

ffeingol

Well-Known Member
PartnerNOC
Nov 9, 2001
493
143
343
cPanel Access Level
DataCenter Provider
The problem is (and I'm sure others will confirm) is that if you create a databases outside the way that cPanel wants to do it (using the GUI or the API) cPanel does not "know" about the databases. It won't show up in phpMyAdmin, it won't get backed up etc.

If you don't want to work with cPanel the way that cPanel works, then it's prob. not the right platform for you.
 
  • Like
Reactions: cPanelLauren