1

I wanted to quickly pull all the data (contacts, custom types, etc) from one Drupal CiviCRM install to another.

I got a little too clever for myself and used Drush sql-sync to do it. It failed. As I was in a hurry and it seemed to be a permissions issue I re-ran the import as the DB root. This worked, and the site appears to work fine. However, Drush sql-sync now always fails when I try to pull from live to staging or to dev servers.

After much digging I realised the original sql query included a number of triggers related to the user of the copied website, eg:

 1156 DELIMITER ;;
 1157 /*!50003 CREATE*/ /*!50017 DEFINER=`source_user`@`localhost`*/ /*!50003 TRIGGER civicrm_activity_before_insert before insert ON civicrm_activity FOR EACH ROW BEGIN  
 1158 SET NEW.created_date = CURRENT_TIMESTAMP;
 1159  END */;;

I assume I want to change these entries, is there a "safe" way to go about that?

Is the presence of these bad for the site?

The source_user has no grants on the new site.

There are at least 60 or so references to the database user in civiCRM related triggers and definitions.

As an aside, Why does civi need to do this when there is a settings file?

2

In stead of using drush for this, I use the "mysqldump --skip-triggers"command exactly for that reason:

mysqldump --skip-triggers -u db_user -pdb_password db > export.sql
3

Civicrm utilises sql triggers for a number of purposes - including but not limited to populating values into the log_civicrm_% tables - if you have logging turned on under Admin -> System Settings -> Misc

You can't alter triggers. Easiest to dump the database then strip out triggers using the following perl

perl -pi -e 's#\/\*\!5001[7|3].*?`[^\*]*\*\/##g' /path/to/mysqldump.sql

by way of Jon G and Chris Burgess on Why do I get "Access denied; you need (at least one of) the SUPER privilege(s) for this operation" when importing a SQL dump to CiviCRM?

after you import Civicrm will rebuild triggers as needed.

  • Can I import just the triggers updated for the correct user, or do I have to completely rebuild my civi DB? – tanbog Dec 18 '18 at 0:26
  • 1
    If you want you could attempt to get a list of all triggers then drop them one by one. Something similar to the following might work. - I haven't tested this sorry. mysql --skip-column-names -B -e "select trigger_schema, trigger_name from information_schema.triggers where trigger_schema ='database_name' limit 10" | awk '{printf("drop trigger if exists %s.%s;\n", $1, $2)}' – Luke Stewart Dec 18 '18 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.