# MySQL Reverse ETL Source

<p><a href="https://www.mysql.com/" >MySQL</a> is a popular open source relational DBMS.</p>
<p>RudderStack supports MySQL as a data source from which you can ingest data and route it to your desired downstream destinations.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">This source is compatible with MySQL v8.0.0 and above.</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="granting-permissions">Grant permissions</h2><p>Before you set up MySQL as a source, you must grant certain permissions on your MySQL database for RudderStack to access data from it.</p>
<p>Run the SQL queries listed in the following sections in the  <strong>exact order</strong> to grant these permissions:</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="step-1-creating-the-user">Step 1: Create user</h3><p>Create a new user <code>RUDDER</code> with a password <code>&lt;password&gt;</code> in MySQL:</p>
<div class="rs-code">
  <div class="rs-code__head">sql<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-sql" data-lang="sql">CREATE USER RUDDER IDENTIFIED BY &#39;&lt;password&gt;&#39;;</code></pre></div>
</div>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">Set a strong and unique password for creating the user in MySQL.</div>
  </div>
</blockquote>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="creating-the-rudderstack-schema-and-granting-permissions">Step 2: Create RudderStack schema and grant permissions</h3><ol>
<li>Create a dedicated schema <code>_rudderstack</code>.</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">sql<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-sql" data-lang="sql">CREATE SCHEMA _rudderstack;</code></pre></div>
</div>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><p>The <code>_rudderstack</code> schema stores Reverse ETL sync state, snapshots, and related tables. <strong>Do not change this name</strong>.</p>
<p>See <a href="https://www.rudderstack.com/docs/data-pipelines/reverse-etl/developer-guides/rudderstack-schema/" ><code>_rudderstack</code> Schema Reference</a> for more details.</p>
</div>
  </div>
</blockquote>
<ol start="2">
<li>Grant full access to the schema <code>_rudderstack</code> for the user <code>RUDDER</code>.</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">sql<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-sql" data-lang="sql">GRANT ALL PRIVILEGES ON _rudderstack.* TO RUDDER;</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="step-3-granting-permissions-on-your-schema-and-table">Step 3: Grant permissions on schema and table</h3><ol>
<li>Grant access to the user <code>RUDDER</code> to read data from tables in <code>&lt;YOUR_SCHEMA&gt;</code>:</li>
</ol>
<div class="rs-code">
  <div class="rs-code__head">sql<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-sql" data-lang="sql">GRANT SELECT ON  &lt;YOUR_SCHEMA&gt;.* TO RUDDER;</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="setting-up-the-mysql-source-in-rudderstack">Set up MySQL source in RudderStack</h2><ol>
<li>Log in to your <a href="https://app.rudderstack.com/" >RudderStack dashboard</a>.</li>
<li>On the <strong>Connections</strong> page, click <strong>Add source</strong>.</li>
<li>Under <strong>Sources</strong>, click <strong>Reverse ETL</strong> and select <strong>MySQL</strong>.</li>
</ol>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="configuring-the-connection-credentials">Configure warehouse credentials</h3><p>You can choose to proceed with your existing warehouse credentials if you have configured them in the RudderStack dashboard previously. Otherwise, click <strong>Add new credentials</strong> to add new credentials for your warehouse.</p>
<ul>
<li><strong>Host</strong>: Enter the host name of your MySQL instance.</li>
<li><strong>Port</strong>: Enter the port number associated with the MySQL database instance.</li>
<li><strong>Database</strong>: Enter the database name in your MySQL instance from where RudderStack ingests the data.</li>
<li><strong>User</strong>: Enter the user name of your MySQL instance.</li>
<li><strong>Password</strong>: Enter the password for the above user.</li>
<li><strong>SSL Mode</strong>: Select the SSL mode from <strong>false</strong> or <strong>skip-verify</strong> depending on how RudderStack should connect to your MySQL instance.</li>
</ul>
<p>Click the <strong>Verify</strong> button on the top right. RudderStack will then <a href="#faq" >verify and validate your credentials</a>. Once verified, click <strong>Continue</strong> to proceed.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="specify-name-and-source-type">Specify name and source type</h3><ul>
<li><strong>Source name</strong>: Assign a name to uniquely identify the source in the RudderStack dashboard.</li>
<li><strong>Select your source type</strong>: RudderStack lets you set up a Reverse ETL source from a warehouse <strong>Table</strong> or <strong>Model</strong>.</li>
</ul>
<table>
  <thead>
      <tr>
          <th>Source type</th>
          <th>Description</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Table</td>
          <td>Use an existing warehouse table as a data source. <br /><br />See <a href="#use-warehouse-table-as-source" >Use warehouse table as source</a> for detailed setup.</td>
      </tr>
      <tr>
          <td>Model</td>
          <td>Use custom SQL queries to fetch specific warehouse data and send them to your destinations. <br /><br />See <a href="#use-model-as-source" >Use model as source</a> for detailed setup.</td>
      </tr>
  </tbody>
</table>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="use-warehouse-table-as-source"><strong>Use warehouse table as source</strong></h4>

<p>Under <strong>Select your source type</strong>, choose <strong>Table</strong> and specify the below fields:</p>
<ul>
<li><strong>Schema</strong>: Select the warehouse schema from the dropdown.</li>
<li><strong>Table</strong>: Choose the required table from which RudderStack syncs the data.</li>
<li><strong>Primary key</strong>: Select the column from the above table that uniquely identifies your records in the warehouse.</li>
</ul>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>RudderStack uses the primary key column for diffing in case of incremental syncs. You can generate it by:</p>
<ul>
<li>Generating your table with a primary key, OR</li>
<li>Creating a table view</li>
</ul>
<p>You can use a composite key in cases where one column cannot be considered as a primary key. For example, you can a declare a composite key of <code>user_id</code> and <code>timestamp</code> by creating a view on your warehouse table.</p>
</div>
  </div>
</blockquote>

</html>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/wh-table-source.webp"
        
        >
        <img src="/docs/images/retl-sources/wh-table-source.webp" 
         alt="Use table as source"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>Finally, <a href="#review-and-complete-setup" >review and complete</a> your source setup.</p>

<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="use-model-as-source"><strong>Use model as source</strong></h4>

<p>Under <strong>Select your source type</strong>, choose <strong>Model</strong> and click <strong>Continue</strong>.</p>
<p>To configure a model as source:</p>
<ol>
<li>Enter an optional description and specify the custom SQL query in <strong>Query</strong> section.</li>
<li>Click <strong>Run Query</strong> to fetch the data preview.</li>
<li>Select the <strong>Primary key</strong> to use a column that uniquely identifies your warehouse records.</li>
</ol>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">You can set a primary key only after you run the SQL query successfully using the <strong>Run Query</strong> option.</div>
  </div>
</blockquote>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>RudderStack uses the primary key column for diffing in case of incremental syncs. You can generate it by:</p>
<ul>
<li>Generating your table with a primary key, OR</li>
<li>Creating a table view</li>
</ul>
<p>You can use a composite key in cases where one column cannot be considered as a primary key. For example, you can a declare a composite key of <code>user_id</code> and <code>timestamp</code> in SQL query of the model.</p>
</div>
  </div>
</blockquote>

</html>

<figure class="image--main "  >
    <a 
         href="/docs/images/data-pipelines/model-source-configuration.webp"
        
        >
        <img src="/docs/images/data-pipelines/model-source-configuration.webp" 
         alt="Model configuration"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>Finally, <a href="#review-and-complete-setup" >review and complete</a> your source setup.</p>

<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="review-and-complete-setup">Review and complete setup</h3>

<p>To make any changes to the warehouse credentials or source configuration, click the edit icon present next to those sections.</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/edit-source-configuration.webp"
        
        >
        <img src="/docs/images/retl-sources/edit-source-configuration.webp" 
         alt="Edit source configuration"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>Review your configuration and click <strong>Create source</strong> to complete the setup.</p>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="connect-destination">Connect destination</h2>

<p>To start using the newly-created source, you can connect it to:</p>
<ul>
<li>A new <a href="https://www.rudderstack.com/docs/destinations/overview/" >destination</a>, or</li>
<li>An existing destination that is <strong>not already connected</strong> to any other source.</li>
</ul>
<p>To connect to a destination later, click <strong>Done</strong> on the top right:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/created-source.webp"
        
        >
        <img src="/docs/images/retl-sources/created-source.webp" 
         alt="Next steps"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>You will then be redirected to the <strong>Overview</strong> page of the source where you will see the option of connecting it to a new or existing destination.</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/add-destination.webp"
        
        >
        <img src="/docs/images/retl-sources/add-destination.webp" 
         alt="Add destination"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>See <a href="https://www.rudderstack.com/docs/data-pipelines/reverse-etl/developer-guides/retl-connection-setup/" >Set up Reverse ETL Connection</a> section for more information.</p>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="update-source-configuration-and-settings">Update source configuration and settings</h2><p>Go to the <strong>Configuration</strong> tab of your Reverse ETL source to update the configuration depending on your source type:</p>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">You cannot change the source type on this page.</div>
  </div>
</blockquote>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/update-source-configuration.webp"
        
        >
        <img src="/docs/images/retl-sources/update-source-configuration.webp" 
         alt="Update source configuration"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>The below table lists the options you can update:</p>
<table>
  <thead>
      <tr>
          <th>Source type</th>
          <th>Configurable options</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Table</td>
          <td><a href="#use-warehouse-table-as-source" >Schema, Table, Primary key</a></td>
      </tr>
      <tr>
          <td>Model</td>
          <td><ul><li><a href="#use-model-as-source" >Model settings</a></li><li><a href="#use-model-as-source" >Primary key</a></li></ul><strong>Note</strong>: You can set the primary key only after the SQL query runs successfully.</td>
      </tr>
  </tbody>
</table>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">After updating the configuration, the next sync will be a full sync.</div>
  </div>
</blockquote>

</html>
<p>Go to the <strong>Settings</strong> tab to:</p>
<ul>
<li>Get your source ID.</li>
<li>Change your warehouse credentials.</li>
<li><a href="https://www.rudderstack.com/docs/monitor/alerts/" >Set up custom alerts</a> for your Reverse ETL source.</li>
<li>Delete the source permanently.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">You cannot delete a source that is connected to any destination.</div>
  </div>
</blockquote>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/source-settings.webp"
        
        >
        <img src="/docs/images/retl-sources/source-settings.webp" 
         alt="Edit source settings"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="faq">FAQ</h2><!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="what-do-the-three-validations-under-verifying-credentials-imply"><strong>What do the three validations under Verifying Credentials imply?</strong></h4><p>When setting up a Reverse ETL source, you will see the following three validations under the <strong>Verifying Credentials</strong> option once you proceed after entering the warehouse credentials:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/retl-sources/retl-credentials-validate.webp"
        
        >
        <img src="/docs/images/retl-sources/retl-credentials-validate.webp" 
         alt="Validating credentials"  
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>These options are explained below:</p>
<ul>
<li><strong>Verifying Connection</strong>: This option indicates that RudderStack is trying to connect to the warehouse with the provided warehouse credentials.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">If this option gives an error, it means that one or more fields specified in the warehouse credentials are incorrect. Verify your credentials in this case.</div>
  </div>
</blockquote>
<ul>
<li><strong>Able to List Schema</strong>: This option checks if RudderStack is able to fetch all schema details by using the provided credentials.</li>
<li><strong>Able to Access RudderStack Schema</strong>: This option implies that RudderStack is able to access the <code>_rudderstack</code> schema you have created by running all commands in the <a href="#creating-the-rudderstack-schema-and-granting-permissions" >User Permissions</a> section.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">If this option gives an error, verify if you have successfully created the <code>_rudderstack</code> schema and given RudderStack the required permissions to access it.</div>
  </div>
</blockquote>

