Creating a stripped-down version of the original AdaptiveDB
Posted by mholmes on 28 Nov 2011 in Activity log
JW reported that the number of custom fields has grown to the point where the db is unusably slow, and she needs to work with a subset of it. After getting details of what can be dropped, I figured out, tortuously, a procedure to build a cut-down version of the db.
- Create a backup from phpMyAdmin.
- Open the backup in a text editor and replace all instances of DEFINER=`hcmc`@`lettuce.tapor.uvic.ca` with DEFINER=CURRENT_USER. (If you don't do this, when you later try to dump the trimmed database, the dump will fail because the definer will not be a user on the local host.)
- Install mysql-server-5.1 locally, and go through all the recommended security settings (this helped).
- Log into mysql (
mysql -u root -p
). create database tempAdaptive;
- From a regular command line, put your backup data into the new db:
mysql -u root -p[password] tempAdaptive < /path/to/dump.sql
Remember there's no space after -p. - Log back into mysql, and start trimming (see commands below).
- When the db is trimmed down, dump out the results:
mysqldump -u root -p[password] --add-drop-database --databases tempAdaptive > /path/to/dump.sql
- Stop your local mysql server:
sudo service mysql stop
- Put the dump file up on
home1t/hcmc/temp
. - Log into mysqldev.tapor.uvic.ca as hcmc, and navigate to that folder.
- Log into mysql, and create tempAdaptive.
- Log out of mysql, and restore:
mysql -u hcmc -p[password] tempAdaptive < tempAdaptive.sql
- Log into phpMyAdmin and give the regular Adaptive DB user the same privileges as on the original db.
- [Starting tomorrow] Build a stripped-down AdaptiveDB site for this dataset.
This is the trimming I had to do for this particular situation:
DELETE from documents where NOT(doc_to_docTypes_id="1" AND exists (SELECT * FROM docs_to_docPeriods WHERE docs_to_docPeriods.dtp_doc_id_fk = documents.doc_id AND docs_to_docPeriods.dtp_docPeriod_id_fk="2")); alter table documents drop foreign key documents_ibfk_2; alter table documents drop column doc_to_projects_id; alter table documents drop foreign key documents_ibfk_4; alter table documents drop column doc_to_docPeriods_id; alter table documents drop foreign key documents_ibfk_3; alter table documents drop column doc_to_docStatusVals_id; alter table documents drop column doc_notBefore; alter table documents drop column doc_notAfter; drop table docs_to_chapters; drop table docs_to_disStatus; drop table docStatusVals; drop table documentsBack; drop table projects; drop table customFieldDataBack; drop view documents_view; drop view VW_doc_authConcerns_concat; drop view VW_doc_chapters_concat; drop view VW_doc_disStatus_concat; drop view VW_doc_disTopics_concat; drop view VW_doc_disTypes_concat; drop view VW_doc_docPeriods_concat; drop view VW_doc_meetPlaces_concat; drop view VW_doc_news_concat; drop view VW_documents_all; drop function cf_bool_to_otm; delete from customFields where cf_id in (95,46,5,44,4); DELETE FROM customFields where cf_group_1 LIKE "Sedition concepts%"; DELETE FROM customFields where cf_group_1="Temporary flags - for topic sorting"; DELETE FROM customFields where cf_group_1="Sandbox";