🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms MySQL Database Integration Add-on

Updated 9 min read Gravity Forms Files, Storage & Databases
On this page
  1. System requirements
  2. Install and activate
  3. Step 1: Prepare the database user
  4. Step 2: Connect in the add-on settings
  5. Step 3: Create a feed
  6. Insert or update
  7. How values are saved
  8. Retries, errors and double rows
  9. Send old entries
  10. Security
  11. Troubleshooting
  12. Developer hooks
  13. Frequently asked questions
  14. Can I write to a database on another server?
  15. Does the add-on change the WordPress database?
  16. How does it prevent SQL injection?
  17. Can several forms write to the same table?
  18. Are MariaDB and MySQL both supported?

The Gravity Forms MySQL Database Integration Add-on writes every Gravity Forms entry as a row into your own MySQL or MariaDB database. You choose the table, map form fields to columns (or let the add-on create the table and columns from the form), and decide whether a row is inserted or updated. Writes run in the background, so the form never waits for your database, and a database that is down is tried again later without double rows. Version 2.0.0 is a full rebuild: earlier versions only added an entry note and never connected to a database.

System requirements

  • WordPress 5.8 or newer and Gravity Forms 2.5 or newer.
  • PHP 7.4 or newer with the mysqli extension (the add-on shows a notice if mysqli is missing). The PDO driver alone is not used.
  • MySQL 5.7 or 8.x, or MariaDB 10.3 or newer, on this server or another one.
  • Outbound access from your web server to the database host and port (3306 by default). For a database on another server, allow the web server address in the database firewall and in the user grants.

Install and activate

  1. Download the ZIP from My Account, Downloads on your GravityExtra account.
  2. In WordPress go to Plugins, Add New, Upload Plugin, choose the ZIP and activate it. If you run version 1.0.x, install the ZIP over it: WordPress replaces the old plugin, your saved settings and feeds are kept, and the saved password is encrypted automatically.
  3. Go to Forms, Settings, MySQL DB Add-On and enter your licence key under Gravity Extra License. Nothing is written until the key is accepted.

New versions appear under Dashboard, Updates like any other plugin.

Step 1: Prepare the database user

Make a user that can only reach the one database, from the address of your web server. Insert-only is enough when the tables already exist and you map the columns yourself:

CREATE USER 'gf_sync_user'@'YOUR_WEBSERVER_IP' IDENTIFIED BY 'a-long-random-password';
GRANT SELECT, INSERT ON target_database.* TO 'gf_sync_user'@'YOUR_WEBSERVER_IP';

Add what the feed needs: UPDATE for the update module, and CREATE and ALTER if you turn on Create the table and add new columns. SELECT is used to read the columns of the table (SHOW COLUMNS). If the database is on another server, make sure it listens on a public or private address your web server can reach (bind-address in my.cnf) and that the firewall lets your web server in.

Step 2: Connect in the add-on settings

  1. Open Forms, Settings, MySQL DB Add-On.
  2. Enter Host (a name or an address, for example db.yourcompany.com; localhost for a database on the same server), Port (empty means 3306), Database Name and Username.
  3. Type the Password. It is stored encrypted with your site keys and is never shown again; leave the box empty to keep the saved one, or tick Remove the stored password for a user without a password.
  4. Choose the Encrypted connection: Off, On, and check the server certificate (recommended when the database is on another server; add a CA certificate file path if your server uses its own authority) or On, without checking the certificate.
  5. Click Test connection. You see the server version, the database, and whether the connection is encrypted. The test uses the values on the screen, or the saved password when the box is empty. No row is written.
  6. Click Save Settings.

Write while the visitor waits is off by default: the entry is queued and written a moment later by WordPress cron. Turn it on only if you need the row to exist before the confirmation page shows; a slow database then slows that visitor down (the connection waits at most 5 seconds to connect and 15 seconds for an answer).

MySQL DB Add-On settings with host, port, database, user, password, SSL choice and Test connection
Figure 1: Forms, Settings, MySQL DB Add-On: the connection settings.

Step 3: Create a feed

  1. Open the form, then Settings, MySQL DB Add-On, and click Add New.
  2. Feed Name: any name, for example Insert leads into CRM database.
  3. Table Name: the table that gets one row per entry, written exactly as it is in the database. Database (optional) sends this feed to another database on the same server.
  4. Module: Insert Row, or Insert or update the row (upsert on a key column) (see below).
  5. Columns: I choose the columns shows the Column Mapping table, where you type the column name and pick a form field, an entry detail (entry ID, form ID, date, source URL, user ID, payment fields, IP address) or a custom value with merge tags. Build the columns from the form fields names the columns after the field labels (or field IDs) and lets you tick the entry details to add.
  6. Lists: checkboxes and multi selects are saved as a JSON list (["Data","Ops"]) or as comma separated text.
  7. Create the table and add new columns: when ticked, a missing table is created and a missing column is added. Existing columns are never changed or deleted. The table is created as InnoDB with utf8mb4 and an automatic id column.
  8. Enable Condition: tick it to write only the entries that match your rules.

You can add several feeds to one form, and several forms can write to the same table.

MySQL feed settings with the Insert or update module and a key column
Figure 2: A feed that inserts or updates a row, with the columns built from the form.

Insert or update

  • Insert Row adds a row for each entry. Give the feed an Entry reference column if you want a guarantee against double rows: the column gets a code such as gf3-e127-f9 and a UNIQUE index (created for you when table maintenance is on), so the same entry can never be inserted twice, even if a send is repeated.
  • Insert or update the row needs a Key column: a mapped column with a UNIQUE or PRIMARY index, such as the entry ID. A row with the same key is updated, otherwise a row is inserted. Without table maintenance the add-on refuses to write when the key has no UNIQUE index, because it could not protect you from double rows.

How values are saved

Form fieldColumn the add-on createsWhat is written
Text, email, radio, select, name and address partsVARCHAR(255)The text as typed.
Paragraph text, addressTEXTThe text as typed, line breaks kept.
Number, quantity, totalDOUBLEA plain number; 1,234.50 and 1.234,50 are read according to the field format.
Date, timeDATE, TIME2027-03-15 and 13:05:00. Dates follow the format of the field.
Checkbox, multi select, list, several filesTEXTA JSON list, or comma separated text.
ConsentTINYINT(1)1 when checked, 0 when not.
Entry ID, form ID, date created (UTC), user IDBIGINT, INT, DATETIMEAs in the entry.

When the table already exists, the real column type decides: a number is sent clean to an INT or DECIMAL column, a date to a DATE column, and a value that does not fit (a word in a number column) is saved as NULL instead of failing. Empty answers are NULL in number, date and time columns and empty text in text columns. If a value is longer than its column, the server refuses it and that entry gets an error note with the server reason; other entries are not affected.

Retries, errors and double rows

  • A database that cannot be reached, a lock timeout and a deadlock are tried again after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours (six attempts in all). The entry shows the last reason.
  • A wrong password, a missing table, an unknown column or a value the column refuses is final: the entry gets an error note at once, with the server message and a hint.
  • If the connection is lost while a row is being written, nobody can know whether the row was saved. With an update key or an entry reference column the add-on tries again and the key makes a repeat harmless. For a plain insert it does not try again; the entry note says the write is not confirmed so you can check the table.
  • Each entry is written once per feed. Two WordPress cron runs cannot write the same entry at the same time.

Send old entries

Open Forms, Entries, select entries (or all) and choose Send to MySQL (skip entries already sent) in the bulk actions. Entries are written in the background, 25 at a time. Entries that were already written are skipped, and a message tells you how many were queued and how many skipped. For feeds with an update key or a reference column, Send to MySQL again writes entries again; the key keeps the table free of double rows.

Entry list with the Send to MySQL bulk action
Figure 3: Forms, Entries: the Send to MySQL bulk action.
Entry with the note Row inserted into MySQL table
Figure 4: Every entry gets a note that says what happened in the database.

Security

  • Every value travels as a bound parameter of a prepared statement (mysqli). Values are never put into the SQL text.
  • Table and column names are always written between backticks with any backtick doubled, and names with control characters or more than 64 characters are refused. Field labels are only used to make simple column names (lower case letters, numbers and underscores).
  • The password is encrypted at rest with your site keys. If you change the authentication keys in wp-config.php, enter the password again. Entry notes and the test result never contain it.
  • Use the encrypted connection when the database is not on the same server, and give the user only the rights the feed needs.

Troubleshooting

MessageLikely causeWhat to do
MySQL error 2002 or 2003The server cannot be reached.Check host and port, the firewall, and bind-address. The add-on retries by itself.
MySQL error 1045Wrong user name or password.Fix the settings and save. Entries that failed can be sent again from the entry list.
MySQL error 1130The database does not allow your web server address.Grant the user from the address of your web server.
MySQL error 1049The database name is wrong.Check Database Name in the settings or in the feed.
The table does not existTable name typed differently, or no table yet.Fix the name, or tick Create the table and add new columns.
The table has no column …A mapped column name is not in the table.Fix the name (names are case sensitive on most Linux servers) or tick table maintenance.
MySQL error 1406 or 1265A value is longer than its column or does not fit it.Make the column longer (for example TEXT).
Cannot connect using SSLThe server has no TLS, or the certificate is not trusted.Turn TLS on at the server, add the CA certificate file, or switch to the unchecked option for a test.

Developer hooks

// Change the values of a row before it is written. $row is column name => value.
add_filter( 'gemy_row', function ( $row, $feed_id, $entry, $form ) {
    $row['source'] = 'website';
    return $row;
}, 10, 4 );

// Run code after a row was written. $action is inserted, updated, unchanged or exists.
add_action( 'gemy_sent', function ( $entry, $feed, $form, $action ) {
    error_log( 'MySQL row ' . $action . ' for entry ' . $entry['id'] );
}, 10, 4 );

Frequently asked questions

Can I write to a database on another server?

Yes. Enter its host name or address and port, use the encrypted connection, and allow your web server in the database firewall and in the user grants.

Does the add-on change the WordPress database?

No. It only connects to the database you enter. Tables of WordPress are not touched.

How does it prevent SQL injection?

With prepared statements for every value and escaped names for every table and column, as described under Security.

Can several forms write to the same table?

Yes. Make one feed per form and point them to the same table; use the same column names.

Are MariaDB and MySQL both supported?

Yes: MySQL 5.7 and 8.x and MariaDB 10.3 or newer. The add-on uses only the standard client protocol and plain SQL.

Still need help?

Our support team answers tickets every day, usually within a few hours.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr