set_mysql_password in postwwwacctuser fails

tgv

Member
May 29, 2008
9
0
51
Hi there,

So I'm refactoring my old trusty postwwwacctuser bash script, part of which creates a database user with strong password and adds its credentials to .my.cnf -- basically for later use with the famous automysqlbackup script.

Now, instead of creating a new user, I started trying to update the default MySQL user for an account with the new password.

All excited about the new(ish) WHM API, I was trying to update the password doing it this way:

Code:
#!/bin/bash

CPUSER=$1
DBUSER=${CPUSER}
DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 16)
CNF=/home/${CPUSER}/.my.cnf

#https://confluence2.cpanel.net/display/SDK/WHM+API+1+Functions+-+set_mysql_password
whmapi1 set_mysql_password user=${DBUSER} password=${DBPASS} cpuser=${CPUSER}
The problem is with the cpuser parameter:

- if it's the newly created account user then error looks like
API failure: (XID 94f5bn) The system user “db” does not control a MySQL user named “db”.
- if it's root,
API failure: (XID wq359f) The cPanel user “root” does not exist in the database map.
Both messages do not make any sense to me.

So my questions are:
- why interactive "SQL Services > Change MySQL User Password" feature works and API call doesn't?
- what's wrong with the default MySQL user? should I leave it alone? why?
 
C

cPanelUser-Inactive

Guest
There's definitely something wrong with our documentation on that whmapi call, so I've submitted an internal case to get that clarified and updated. In the meantime: I do something similar in a script that I use for setting up a server for testing. For my uses, the uapi is better than trying to use the WHMAPI. Maybe that will work for you?

uapi --user=$cPanelUser Mysql create_database name=$cPaneluser_db1
uapi --user=$cPanelUser Mysql create_user name=$cPanelUser_user1 password=$password
uapi --user=$cPanelUser Mysql set_privileges_on_database user=$cPanelUser_user1 database=$cPanelUser_db1 privileges=DELETE,UPDATE,CREATE,ALTER
 

tgv

Member
May 29, 2008
9
0
51
Thanks Benny,

Unfortunately uapi doesn't work either when I try to do things with the default user, similar error messages.

Just to clarify, the original idea was to create a user with access to all account databases (before they exist!) to facilitate daily backups. We do that because it's convenient to have a pile of database dumps aside of huge account archives.

At first I was auto-creating a user with access to accountname\_% and it kinda worked fine except cPanel interface didn't know how to deal with these users and I had a huge pain mass-migrating accounts. That was years ago, can I ask -- do cPanel GUI, API, migration script etc. support wildcard database names now, in 2016?

Then I wanted to make use of the invisible and barely documented default MySQL user, which has access to every database already. The only issue is feeding credentials to the backup script: it can parse .my.cfg file all right but I'm not comfortable leaving account password there, and wanted to change the password to a different one. Still not terribly secure but much better. Apparently this doesn't work through API.

I'm wondering if there's a way for the automysqlbackup script to pick credentials the way phpmyadmin does, is it documented anywhere?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,202
363
At first I was auto-creating a user with access to accountname\_% and it kinda worked fine except cPanel interface didn't know how to deal with these users and I had a huge pain mass-migrating accounts. That was years ago, can I ask -- do cPanel GUI, API, migration script etc. support wildcard database names now, in 2016?
Hello,

I don't recommend using a wildcard for database names, however you may find this script helpful for assigning ownership of a database or database username to a cPanel account:

/usr/local/cpanel/bin/dbmaptool

It's documented at:

The dbmaptool script - Documentation - cPanel Documentation

This thread may also help:

Creating DB, USER, GRANTS and map to an account via SSH

Thank you.
 

tgv

Member
May 29, 2008
9
0
51
Thanks Michael,

I've been using dbmaptool previously in my script, just wanted to move on from it.

Sorry I don't know how to express it any clearer: I don't want to create new users, I just want to modify the existing, default one.
 
Thread starter Similar threads Forum Replies Date
Y Developer Experience 1