Procedure:
We assume here that the only information available to us is the name of the table and we do not know the name of the database it belongs to.
In order to determine who owns a specific MySQL table, first, you need to determine the database that the table belongs to. The best way to achieve this is to log into MySQL as root and run this SQL command:
select table_schema as database_name, table_name from information_schema.tables where table_type = 'BASE TABLE' and table_name = '$TABLE_NAME' order by table_schema, table_name;
You need to replace $TABLE_NAME with the complete name of the table in the command above.
For demonstration purposes, let's look for a table with the name "table1" and to see to what database this table belongs. As previously mentioned, we need to log into MySQL as root and then run the command above:
mysql> select table_schema as database_name, table_name from information_schema.tables where table_type = 'BASE TABLE' and table_name = 'table1' order by table_schema, table_name;
+----------------------+------------+
| database_name | table_name |
+----------------------+------------+
| cptest_test-database | table1 |
+----------------------+------------+
1 row in set (0.01 sec)
As you can see the table belongs to the database named "cptest_test-database". Now the next step is to determine what cPanel user/account is the owner of this database. This can be done using this API function: (You need to replace $DATABASE_NAME with the name of the database from the output above)
whmapi1 list_databases | grep -i $DATABASE_NAME -B 2
Running this command for the database we just found we will get this:
whmapi1 list_databases | grep -i cptest_test-database -B 2
cpuser: cptest
engine: mysql
name: cptest_test-database
This means that the database "cptest_test-database" belongs to the cPanel account/user "cptest"