Renaming an user and move his databases

Zagorax

Verified User
Joined
Jan 11, 2011
Messages
67
Hi all,

I've to rename an user from foo to bar. So, first of all I use the appropriate script:
Code:
cd /usr/local/directadmin/script
./change_username.sh foo bar

Then, since this user has some specific httpd options, I change all occurence of foo to bar in the virtual host template. Then I reload httpd configuration.

Unfortunateli with this solution all database still belongs to no-more existent user foo. And I do not understand how should I recover them. If I do the whole procedure to restore foo user, databases show up again in directadmin, otherwise they simply disappear.

I had tried to do:

Code:
VERBOSE=1 DBUSER="da_admin" DBPASS="da_adminpass" USERNAME="foo" NEWUSERNAME="bar" /usr/local/bin/php /usr/local/directadmin/scripts/change_database_username.php

But nothing changes. The command simply doesn't give any output. I think it's becouse I run it once foo doesn't exists anymore.

Does exist a different solution from dump the database, erase them and restore them with the new user?

Cheers,
Zag
 
The issue with the database when changing a user is indeed a problem.
When the user has only 1 or 2 databases, you can best just make an sql backup of the databases only.
After that, delete the databases.
Then change the users name, create new empty databases and restore the sql backups again. This is way nothing gets lost and databases will work under the new username.

I wouldn't know if there is a better solution when there are lots of databases.
There is a chance however that other idea's/answers will be made later due toe the old year and new year celebration on many country's tonight, so there might not be a lot of people online.
 
DirectAdmin can't manage this because it doesn't know where the database name is listed in your configuration, so you need to do it manually.

I'm not 100% sure but I believe I've in the past simply renamed the database folder/files, and then changed the code in the user's configuration file(s) to use the new database name.

Of course this will only work presuming the database name isn't stored in the database, and I may be misremembering this, so give it a try before depending on it.

Jeff
 
Back
Top