Tech:Renaming a database

From Orain Meta
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.

  1. 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.

  1. mysqldump -u mediawiki -p original_database > original_database.sql
  2. mysql -u mediawiki -p -e "create database my_new_database"
  3. mysql -u mediawiki -p my_new_database < original_database.sql
If renaming a wiki database
  1. mysql -p -u mediawiki -e "UPDATE centralauth.localuser SET lu_wiki = 'newwikidatabase' WHERE lu_wiki = 'oldwikidatabase';"
  2. mysql -p -u mediawiki -e "UPDATE centralauth.localnames SET ln_wiki = 'newwikidatabase' WHERE ln_wiki = 'oldwikidatabase';"
  3. 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.
  4. SSH to a mediawikiserver, and rename the folder /mnt/mediawiki/uploads/old.wiki.domain to /mnt/mediawiki/uploads/new.wiki.domain.
  5. Confirm the wiki works

3. Tidy up

  1. Confirm everything is working as suspected
  2. mysql -u mediawiki -p -e "drop database original_database"
  3. rm original_database.sql