Tech:Renaming a database
Jump to navigation
Jump to search
Sometimes, a database needs to be renamed, as an example because a steward/wiki creator created a database for a wiki without the correct name - though this documentation can be used also to rename non-wiki databases. This process is annoying and should be avoided when possible, as John would say.
1. Show all databases
Identify the database that is incorrect / where we should be pointing.
- mysql -u mediawiki -p -e "show databases"
2. Renaming a mysql database
There is no simple way to do this in mysql. Be sure you know where the sql file will be dumped, like in /root or whatever.
- mysqldump -u mediawiki -p original_database > original_database.sql
- mysql -u mediawiki -p -e "create database my_new_database"
- mysql -u mediawiki -p my_new_database < original_database.sql
- If renaming a wiki database
- mysql -p -u mediawiki -e "UPDATE centralauth.localuser SET lu_wiki = 'newwikidatabase' WHERE lu_wiki = 'oldwikidatabase';"
- mysql -p -u mediawiki -e "UPDATE centralauth.localnames SET ln_wiki = 'newwikidatabase' WHERE ln_wiki = 'oldwikidatabase';"
- Check the ansible-playbook and database list and be sure all references to the old wiki database are gone, and replaced by the new wiki database.
- SSH to a mediawikiserver, and rename the folder /mnt/mediawiki/uploads/old.wiki.domain to /mnt/mediawiki/uploads/new.wiki.domain.
- Confirm the wiki works
3. Tidy up
- Confirm everything is working as suspected
- mysql -u mediawiki -p -e "drop database original_database"
- rm original_database.sql