Keeping your databases secure

Protect your website’s databases: separate users, strong passwords, prepared statements, safe credential storage and backups.

Guide2 min readLast updated
On this page
  1. 1. One user per application
  2. 2. Strong, unique passwords
  3. 3. Prevent SQL injection
  4. 4. Keep credentials out of reach
  5. 5. Don’t leave SQL dumps in public_html
  6. 6. Keep phpMyAdmin access to trusted devices
  7. 7. Back up
  8. Common questions

1. One user per application

Each application gets its own database user with access only to its own database. Managing database users and privileges

2. Strong, unique passwords

Generate them. Never reuse a database password for anything else.

3. Prevent SQL injection

Never build SQL with user input:

// Unsafe
$db->query("SELECT * FROM users WHERE email = '$_POST[email]'");
// Safe
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
$stmt->execute([$_POST['email']]);

Connecting a PHP application to your database

4. Keep credentials out of reach

  • Store configuration outside public_html where possible. Storing configuration and secrets outside public_html
  • Never commit credentials to a public Git repository.
  • Remove backup copies like wp-config.php.bak or config.old from public_html: the server may serve them as plain text.

5. Don’t leave SQL dumps in public_html

A backup.sql file in the web root can be downloaded by anyone who guesses the name. Store exports off the server.

6. Keep phpMyAdmin access to trusted devices

Log out when finished, especially on shared computers.

7. Back up

A secure database you can’t restore is still a single point of failure. A simple backup strategy for your website

Looking for somewhere to run PHP and MySQL? Traxio’s PHP and MySQL hosting includes phpMyAdmin.

Common questions

What is SQL injection?

SQL injection is when input from a visitor is passed into a database query without being handled safely, letting an attacker change what the query does. It is one of the oldest web vulnerabilities and still one of the most damaging.

This is a general web-hosting explanation, not specific to Traxio.

If you write your own PHP, prepared statements are the fix — they keep the query and the data separate so input can never be read as instructions. If you use WordPress, keeping plugins updated is the equivalent defence, because that is where these flaws get found and patched.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going