Creating a database manually

flycast

Member
Feb 20, 2011
11
0
51
I have created a database using sql in a script. When I created the database I was logged in to the MySQL server as the user of the cPanel account. When I go to cPanel for that user and click on "MySQL Databases" the database does not show up in the list of databases.

If I create a database and user while not using cPanel (through phpmyadmin or a script) what do I need to do to make sure that cPanel will list the databases and users and the owner of the account will be able to administer (use, change, delete, etc) the database and user through cPanel?
 
Last edited:

LinuxTechie

Well-Known Member
Jan 22, 2011
502
10
68
cPanel Access Level
Root Administrator
Hello,

The databases created in the cPanel format i.e., cpanel user_databasename will only be listed in Cpanel of the domain. Can you make sure you have created in this format?
 

flycast

Member
Feb 20, 2011
11
0
51
Yes. It was. I created two databases...one through cPanel and one through phpmyadmin. I thin logged into phpmyadmin as root and looked and both databases showed up in the following format:
user
_fromcPanel
_manually
 

flycast

Member
Feb 20, 2011
11
0
51
I just tried the same thing again. The database created in phpmyadmin does not show up in the cPanel listing even though the text in front of the underscore is the cPanel user.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
You cannot use a script or PhpMyAdmin to create databases in this manner in 11.28 onward due to database mapping. Creating a database on a prefixed system will not have it show up in cPanel > MySQL Databases area if created in PhpMyAdmin due to the fact that it doesn't create the necessary yaml files in /var/cpanel/databases/ location to map the database to the user.

You would need to use the API to create databases or otherwise have your script create the necessary mapping for that user with the dbmaptool script. You can use the following script to create a map to the database user:

/usr/local/cpanel/bindbmaptool cpuser --type mysql|pg --dbusers 'user1, user2' --dbs 'db1, db2'

These flags are treated individually. This tool will not map a virtual user to a database.
/usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbs 'db1' --dbusers 'virt1'
/usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbs 'db1' && /usr/local/cpanel/bin/dbmaptool user1 --type mysql --dbusers 'virt1'
The above two commands are analogous; result in cpuser 'user1' having privileges for 'db1' and having a virtual user named 'virt1.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
Correct, that would perform the same function in WHM using the Database Map Tool. Since the requester mentioned a script, I imagined it would be preferred to use the utility in root SSH over the WHM one.
 
A

! am bond

Guest
Was creating DBs through script/ PHPMyadmin disabled?
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
On prefixed systems, you can still create databases via PhpMyAdmin, but those databases will not appear in cPanel > MySQL Databases area due to the fact they aren't mapped properly in /var/cpanel/databases area to the user. As such, it is not advised to create databases through PhpMyAdmin on prefixed systems.

On non-prefixed systems, PhpMyAdmin will display an error upon trying to create a database, so that option would not even be possible to perform.

The option to create databases is still available via the API or if the script calls the dbmaptool function I mentioned to map the database to the user.