CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Import contact into civicrm database from mysql command line
Pages: [1]

Author Topic: Import contact into civicrm database from mysql command line  (Read 2489 times)

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Import contact into civicrm database from mysql command line
June 07, 2011, 01:29:18 pm
Is there anyway to import contacts directly into the database using the MySQL command line. I assume there is, but I`m not entirely sure of what data gets imported into which tables in the database during an import process - where could I find this info?

The reason I am asking, is that we have 750,000 contacts to import. I could do this a lot quicker through the command line than through the GUI. During an election, we may have to import this number of contacts a couple of times a week, and the faster the process, the better.

I know this might not be the most desirable way to import data, but its something I am comfortable with. If anyone has any better suggestions, please let me know - I'm by no means an expert programmer (very much an amateur), so I may need some guidance.

Thanks for any advice.

Brian

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Import contact into civicrm database from mysql command line
June 07, 2011, 09:06:27 pm
Hi,
If you have specific fields of data ( ie know field/columns in csv ), it will be easy to create a custom import script.
here you will get an example  http://civicrm.org/blogs/admin/writing-custom-import-script.

BTW, Import process in current civicrm version is much improved, you might want to check :)

Rajan

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import contact into civicrm database from mysql command line
June 07, 2011, 10:45:39 pm
Hi,

I would use the API and write a script in bin that inherit from bin/cli.php (check other files in it to have an example).

bin/php/import.php does it from a csv.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Import contact into civicrm database from mysql command line
June 08, 2011, 12:46:13 am
& Xavier's blog on csv import to apiv3

http://civicrm.org/blogs/xavier/api_batch_tools
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Import contact into civicrm database from mysql command line
June 08, 2011, 03:29:05 am
Quote from: Eileen on June 08, 2011, 12:46:13 am
& Xavier's blog on csv import to apiv3

http://civicrm.org/blogs/xavier/api_batch_tools

Thanks for the tips. In Xavier's blog above, what exactly do I enter at -syoursite? Is it my domain name? Path to drupal root? Path to civicrm root?

Brian

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Import contact into civicrm database from mysql command line
June 08, 2011, 06:18:33 am
Ok, nevermind. I figured out -syoursite means -syoursitekey.

Now I have another question. I am trying to follow along with Xavier's blog, by using some of the code. I am trying to export my tags just for practice.

So from the shell, I enter:

Code: [Select]
php bin/csv/export.php -uyourlogin -pyourpass -syoursite Tag > /tmp/tagall.csv
and I get the following error message:

Code: [Select]
The system cannot find the file path specificed
which I assume is to do with the /tmp/tagall.csv. When I run the export.php does it create the tagall.csv file? Where is the tmp directory located, or supposed to be located?

If I run the code:
Code: [Select]
php bin/csv/export.php -uyourlogin -pyourpass -syoursite Tag
I get the error:
Code: [Select]
Cannot use object of type PEAR_Error as array in path/to/civicrm/bin/cli.php on Line 57
which is the same error I get if I try and import a csv file of tags as per Xavier's blog.

Any thoughts? As you can tell, I'm quite new to this - I really appreciate the help I get here as I play around with Civicrm

Brian

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Import contact into civicrm database from mysql command line
June 08, 2011, 06:37:53 am
Quote from: bpmccain on June 08, 2011, 06:18:33 am
Ok, nevermind. I figured out -syoursite means -syoursitekey.


It's the name of the folder under your/drupal/sites where you have the config (default or your domain name)

Quote from: bpmccain on June 08, 2011, 06:18:33 am

Code: [Select]
php bin/csv/export.php -uyourlogin -pyourpass -syoursite Tag
I get the error:
Code: [Select]
Cannot use object of type PEAR_Error as array in path/to/civicrm/bin/cli.php on Line 57

It means that it can't find PEAR Console module (it's installed in packages/Console)

I don't know why it doesn't find it. might be that your -s param is not pointing to the proper folder.

(btw, if you have any suggestion to formulate better what this s thing is, feel free)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Import contact into civicrm database from mysql command line
June 30, 2011, 05:04:16 pm
Sorry for the not responding to this sooner - I got busy with other projects, but I still haven't figured this out.

I am unfortunately still confused by the -syoursite part.

Quote
It's the name of the folder under your/drupal/sites where you have the config (default or your domain name)

Do you mean civicrm.config.php? Mine is located at your/drupal/sites/all/modules/civicrm. So what would I put for -syoursite?

Secondly, following the code:
Code: [Select]
php bin/csv/export.php -uyourlogin -pyourpass -syoursite Tag > /tmp/tagall.csv
Where is the /tmp/ directory supposed to be located?

Thanks for all the help here. I'm getting there slowly, and I'd be happy to help write a guide to this for rookies like me once I get it under my belt  :)

Brian

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Import contact into civicrm database from mysql command line
July 01, 2011, 12:41:04 pm
Nevermind - I've figured out the API - mostly anyway. A few more steps to go!

I'll start a new topic.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Import contact into civicrm database from mysql command line

This forum was archived on 2017-11-26.