Summary IconKey Takeaways

Extracting marketing data from Salesforce Marketing Cloud to the BigQuery analytics platform requires specialized connectors and data transformation processes. Below are two primary approaches for this migration:

Method 1: Using Hevo
Hevo provides pre-built connectors for Salesforce Marketing Cloud with automated schema mapping, real-time synchronization, and built-in transformations tailored for marketing data and customer journey analytics.

Method 2: Using CSV Files
This method involves exporting data from Salesforce Marketing Cloud to CSV format via data extensions or subscriber lists, then importing these files into BigQuery using the web UI or command-line tools with appropriate schema definitions. While this approach offers flexibility and control, it requires manual handling of data exports, schema mapping, and import scheduling

Integrating Salesforce with MySQL can significantly streamline business operations, making data management more efficient. Salesforce, as a leading CRM platform, holds valuable customer data that businesses need to leverage for insights and decision-making. On the other hand, MySQL, a powerful and reliable database, helps store and organize this data for analysis, reporting, or further processing.

In this blog, I’ll walk you through the steps to seamlessly integrate Salesforce to MySQL, the benefits of this integration, and some best practices to ensure your data is synced effectively. Let’s dive in!

What Are the Popular Ways to Set Up Salesforce to MySQL Integration?

Method 1: Using Hevo Data

Step 1.1: Configuring Salesforce as the Source

  • From the Navigation Bar, go to PIPELINES.
  • Click + CREATE PIPELINE to begin setup.
  • Choose Salesforce as your Source.
  • On the Salesforce Account Setup screen:
    • Select an existing account and hit CONTINUE
    • OR
    • Click + ADD SALESFORCE ACCOUNT to link a new one:
    • Pick your Salesforce environment: Production or Sandbox
    • Log in with your Salesforce credentials
    • Authorize access by clicking Allow
  • You’ll be redirected to the Source Configuration page. Here, define:
    • Pipeline Name: Something unique (within 255 characters)
    • Authorized User Account: Auto-filled with the connected email
    • Historical Sync Duration: Choose how much past data you want to pull (default: 3 months)
  • Choosing All Available Data will fetch everything since Jan 1, 1970.
  • Set advanced preferences (Optional)
  • Include New Objects:
    • Enabled: Hevo will auto-ingest newly created objects
    • Disabled: New objects stay in SKIPPED state until manually added

          Note: If you run sync for a new object manually, only incremental data is pulled at first. Historical sync kicks off in the next cycle. If a previously deleted object is re-created, Hevo resumes syncing it automatically.

          Once done, click CONTINUE to proceed to ingestion and Destination setup.

          Salesforce to MySQL

          Step 1.2: Configure MySQL as Your Destination

          • Go to the DESTINATIONS tab in the top menu and click + CREATE DESTINATION.
          • Choose MySQL from the available destination types.
          • On the setup screen, fill in the required details:
            • Destination Name – A name to help you identify this setup later.
            • Database Host & Port – Typically your server IP or DNS, and port 3306 by default.
            • User Credentials – The database username and password with necessary write permissions.
            • Database Name – The schema where Hevo will load your data.
          • For more security: 
            • Enable SSH for secure tunneling, or
            • Use SSL by uploading your CA file and client certificates.
          • If your column or table names include spaces or special characters, enable Sanitize Table/Column Names to clean them up automatically.
          • Hit TEST CONNECTION to verify your inputs.
          • Once successful, click SAVE & CONTINUE to move to the next step.
          Salesforce to MySQL: Configuring MySQL as Destination

          Method 2: Using Custom Code

          This method requires you to manually build a custom code using various Salesforce APIs to connect Salesforce to MySQL database. It is important to understand these APIs before learning the required steps.

          APIs Required to Connect Salesforce to MySQL Using Custom Code

          Salesforce provides different types of APIs and utilities to query the data available in the form of Salesforce objects. These APIs help to interact with Salesforce data. An overview of these APIs is as follows:

          • Salesforce Rest APIs: Salesforce REST APIs provide a simple and convenient set of web services to interact with Salesforce objects. These APIs are recommended for implementing mobile and web applications that work with Salesforce objects.
          • Salesforce REST APIs: Salesforce SOAP APIs are to be used when the applications need a stateful API or have strict requirements on transactional reliability. It allows you to establish formal contracts of API behavior through the use of WSDL. 
          • Salesforce BULK APIs: Salesforce BULK APIs are tailor-made for handling a large amount of data and have the ability to download Salesforce data as CSV files. It can handle data ranging from a few thousand records to millions of records. It works asynchronously and is batched. Background operation is also possible with Bulk APIs.
          • Salesforce Data Loader: Salesforce also provides a Data Loader utility with export functionality. Data Loader is capable of selecting required attributes from objects and then exporting them to a CSV file. It comes with some limitations based on the Salesforce subscription plan to which the user belongs. Internally, Data Loader works based on bulk APIs. 

          Steps to Connect Using Custom Code

          Step 2.1: Log in to Salesforce using the SOAP API and get the session ID. For logging in, first create an XML file named login.txt in the below format.

          <?xml version="1.0" encoding="utf-8" ?>
          
          <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          
          xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
          
          <env:Body>
          
          <n1:login xmlns:n1="urn:partner.soap.sforce.com">
          
          <n1:username>your_username</n1:username>
          
          <n1:password>your_password</n1:password>
          
          </n1:login>
          
          </env:Body>
          
          </env:Envelope>

          Step 2.2: Execute the below command to log in

          curl https://login.Salesforce.com/services/Soap/u/47.0 -H "Content-Type: text/xml; 
          charset=UTF-8" -H "SOAPAction: login" -d @login.txt

          From the resultant XML, note the session ID. This session ID is to be used for all subsequent requests.

          Step 2.3: Create a BULK API job. To do this, create a text file in the folder named job.txt with the following content.

          <?xml version="1.0" encoding="UTF-8"?>
          
          <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
          
          <operation>insert</operation>
          
          <object>Contact</object>
          
          <contentType>CSV</contentType>
          
          </jobInfo>

          Please note that the object attribute in the above XML should correspond to the object for which data is to be loaded. Here we are pulling data from the object called Contact.

          Execute the below command after creating the job.txt

          curl https://instance.Salesforce.com/services/async/47.0/job -H "X-SFDC-Session: sessionId" -H "Content-Type: application/xml; 
          charset=UTF-8" -d @job.txt

          From the result, note the job id. This job-id will be used to form the URL for subsequent requests. Please note the URL will change according to the URL of the user’s Salesforce organization.

          Step 2.4: Use CURL again to execute the SQL query and retrieve results.

          curl https://instance_name—api.Salesforce.com/services/async/APIversion/job/jobid/batch
          
          -H "X-SFDC-Session: sessionId" -H "Content-Type: text/csv; 
          
          SELECT name,desc from Contact
          Integrate data from Salesforce to MySQL
          Integrate data from Salesforce Marketing Cloud to MySQL
          Integrate data from Salesforce to BigQuery

          Step 2.5: Close the job. To do this, create a file called close.txt with the following entry.

          <?xml version="1.0" encoding="UTF-8"?>
          
          <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
          
          <state>Closed</state>
          
          </jobInfo>

          Execute the below command after creating the file to close the job.

          curl https://instance.Salesforce.com/services/async/47.0/job/jobId -H "X-SFDC-Session: sessionId" -H "Content-Type: application/xml; 
          charset=UTF-8" -d @close_job.txt

          Step 2.6: Retrieve the results id for accessing the URL for results. Execute the below command.

          curl -H "X-SFDC-Session: sessionId" https://instance.Salesforce.com/services/async/47.0/job/jobId/batch/batchId/result

          Step 2.7: Retrieve the actual results using the result ID fetched from the above step.

          curl -H "X-SFDC-Session: sessionId" https://instance.Salesforce.com/services/async/47.0/job/jobId/batch/batchId/result/resultId

          This will provide a CSV file with rows of data. Save the CSV file as contacts.csv.

          Step 2.8: Load data to MySQL using the LOAD DATA INFILE command. Assuming the table is already created, this can be done by executing the below command.

          LOAD DATA INFILE'contacts.csv' INTO TABLE contacts
          
          FIELDS TERMINATED BY ',' 
          
          ENCLOSED BY '"'
          
          LINES TERMINATED BY 'rn' 
          
          IGNORE 1 LINES;

          Alternately, instead of using the bulk API manually, the Salesforce Data Loader utility can be used to export CSV files of objects. The caveat here is that usage of certain Data Loader functionalities is restricted based on the user’s subscription plan.

          There is also a limit to the frequency with which data loader export operations can be performed or scheduled.

          Ready to harness your Salesforce data for deeper analysis?

          Migrate seamlessly to MySQL and transform customer insights into actionable intelligence. Enjoy simplified data access, efficient querying, and full control over your data! Hevo streamlines the process of migrating data by offering:

          • Seamlessly data transfer between Salesforce, MySQL, and 150+ other sources.
          • Risk management and security framework for cloud-based systems with SOC2 Compliance.
          • Always up-to-date data with real-time data sync.

          Don’t just take our word for it—try Hevo and experience why industry leaders like Whatfix say,” We’re extremely happy to have Hevo on our side.” 

          Get Started with Hevo for Free

          What Makes Salesforce the Ultimate CRM Solution?

          Salesforce Logo

          Salesforce is a CRM that makes cloud-based software designed to help businesses connect with their customers in a whole new way. This allows businesses to find more prospects, close more deals, and wow customers with amazing service.

          Salesforce can be accessed through a web browser, mobile app, or desktop application. It allows users to customize and create custom objects, fields, processes, and reports, and integrate Salesforce with other tools to enhance functionality across platforms. Salesforce also provides marketing automation and Artificial Intelligence (AI) capabilities.

          Features of Salesforce

          • Salesforce stores data in a single database schema. There can be a single instance of a software server with multiple tenants.
          • Salesforce Customer 360 unites your teams with a single view of customers.
          • Provides all three services- SaaS, PaaS, and IaaS.
          • Einstein AI helps you predict sales outcomes and customer churn and identify high-value leads.
          • Salesforce SQL lets you run complex queries in the software itself.

          What Makes MySQL the Go-To Database Solution for Developers?

          MySQL Logo

          MySQL, the most popular open-source SQL database management system, is developed, distributed, and supported by Oracle Corporation. MySQL stores relational databases with structures organized into physical files optimized for speed.

          MySQL is integral to many of the most popular software stacks for building and maintaining everything from customer-facing web applications to powerful, data-driven B2B services.

          Features of MySQL

          You can also clone a database for testing in MySQL by migrating MySQL databases between two servers.

          It is ACID compliant, ensuring atomicity, consistency, isolation, and durability for reliable transactions and data integrity.

          It is open source, which means that it is possible for anyone to use and modify the software.

          It is highly compatible with other tools like data warehouses, databases, and Saas tools. You can even connect Excel to MySQL to migrate your data.

          The MySQL database server is fast, reliable, scalable, and easy to use.

          It is optimized for heavy workloads and can handle large datasets efficiently.

          Why Do We Need to Integrate Salesforce and MySQL?

          • Cost Optimization: Salesforce operates on a consumption-based pricing model, which can lead to higher costs for frequent, intensive queries, whereas MySQL is an open-source tool that can lower storage costs for businesses.
          • Centralized Data for Analytics: MySQL allows you to consolidate all your customer data in one place, making it available for overall analysis and reporting.
          • Data Scalability and Performance: Salesforce can become slow or inefficient when handling large volumes of data, especially with older records. MySQL, on the other hand, can handle large datasets effectively.
          • On-Premise Infrastructure: Salesforce is a cloud-native platform, but few businesses prefer to keep their data on-premise. This is where MySQL comes in handy.

          Limitations of Using the Custom Code Method

          • High Development Time: Creating custom solutions often requires significant time investment for coding, testing, and deployment.
          • Increased Maintenance Overhead: Custom code needs regular updates and monitoring, leading to ongoing maintenance challenges.
          • Skill Dependency: Requires specialized skills in programming and architecture, making it difficult to manage if the original developer is unavailable.
          • Scalability Issues: Custom solutions may struggle to scale efficiently as data volume grows or business needs change.

          Best Practices for Salesforce to MySQL Migration

          • During the migration process, utilizing Salesforce Debug Logs can help identify data inconsistencies and ensure a smoother transfer.
          • Determine which Salesforce objects (e.g., Accounts, Contacts, Opportunities) you need to replicate.
          • After migrating data from Salesforce to MySQL, implementing MySQL Master-Slave Replication can enhance data availability and load balancing.
          • Leverage Salesforce APIs (like Salesforce REST or Bulk API) to fetch only the updated records since the last replication, minimizing data transfer and load on both systems.

          Use Cases of Salesforce MySQL Integration

          • Centralized Customer Data – Store and manage Salesforce data in MySQL for better reporting and analysis.
          • Real-Time Analytics – Sync data for real-time insights and business decisions.
          • Automated Workflows – Connect Salesforce with backend systems to automate processes.
          • Enhanced Marketing & Sales – Use MySQL data to improve targeting and personalization.

          Conclusion

          In this blog, you explored how to achieve Salesforce to MySQL Integration using two different approaches. Additionally, it has also highlighted the limitations and challenges of using the custom code method.

          A more graceful method to achieve the same outcome would be to use a code-free data integration Platform like Hevo Data. Hevo can mask all the ETL complexities and ensure that your data is securely moved to MySQL from Salesforce in just a few minutes and for free.

          Want to take Hevo for a ride? Sign up for a 14-day free trial and simplify your Data Integration process. Do check out the pricing details to understand which plan fulfills all your business needs.

          FAQs

          1. How to connect Salesforce to MySQL Database?

          Salesforce can be connected with MySQL by using an automated data pipeline like Hevo or by writing custom code using Salesforce APIs.

          2. Is Salesforce compatible with SQL?

          Salesforce is compatible with SQL-like queries through its own query language, SOQL (Salesforce Object Query Language), but it doesn’t use traditional SQL.

          3. Can Salesforce be used as a database?

          Salesforce is not a traditional relational database but can store and manage data using its cloud-based CRM platform, which functions similarly to a database for customer-related information.

          mm
          Principal Frontend Engineer, Hevo Data

          With over a decade of experience, Suraj has played a crucial role in architecting and developing core frontend modules for Hevo. His expertise lies in building scalable UI solutions, collaborating across teams, and contributing to the open-source community, showcasing a deep commitment to innovation in the tech industry.