Today we will discuss using SQLite database with WordPress. Maybe you are asking why would I want to use a different database than the standard MySQL?
Over the years there have been many cases where I did not need a dedicated MySQL database for a simple WordPress blog implementation. Or I needed to host a WordPress installation on a server that did not have MySQL. Many cheap shared hosts have busy servers and bypassing their MySQL database can really speed up a WordPress site.
A little history if you wish, if not skip over and learn about using SQLite with a WordPress installation.
It all began about 4 years ago (at least for me) when I discovered this GitHub repository. I still use this method from time to time and it still works ok.
From my understanding this GitHub repository may soon be archived, but fear not the official WordPress Core Team is at work on a new plugin / method!
Let's get started on using the official WordPress SQLite implementation. This is the preferred method. You can read about the status on Make.WoredPress.org.
Visiting the above official WordPress site, please review and use the "Option 2 Method".
I have tested the "Option 1 Method" and was not happy at all. In my short testing it slowed WordPress down and it was a fresh install with little content.
Your choice but I really recommend "Option 2 Method" using the stand-alone plugin.
I HIGHLY recommend that you start with a fresh installation of WordPress. At this point in time the conversion from MySQL to SQLite does not transfer existing data. In other words, you start with a blank fresh install after converting to SQLite.
I now assume you have a fresh working install of WordPress using MySQL method and you know how to install plugins from the official repository.
Using Option 2 – Utilizing the stand-alone plugin:
Begin by installing and activating the SQLite Database Integration plugin on your website. Inside your WordPress install / plugins area, search for "SQLite Database Integration" and MAKE SURE the author is "The WordPress Team". Alternatively you can visit the repository here.
Adhere to the instructions presented on the screen.
- Once you click the button to install the SQLite database, the plugin will automatically transfer the db.php file to your wp-content folder, subsequently redirecting you to the WordPress installation screen for setting up your new database.
Important note: Activating SQLite will result in the creation of a completely new and separate database for your site. WordPress has designed a straightforward setup process to spare you from the installation screens, but please be aware that *no other data from the original database will be migrated apart from this basic configuration.
- After following the simple steps, you will set up your WordPress
installation again using username / password. But this time you will
be using the SQLite database. The new SQLite database is in
wp-content/database
.
There really is nothing else to it and you have just converted your first WordPress installation from MySQL to SQLite!
Now understand that you may experience some issues with some plugins. just keep in mind that using SQLite is (at least in my case) for small easy to host installations. I have over 10 simple WordPress blogs based on SQLite and have no issues at all.
Frequently Asked Questions
Will I lose any data?
No. Activating the SQLite implementation will result in the creation of a new database. Your existing database will remain untouched, and should you choose to disable the module, your site will revert to using its prior MySQL database without any alterations.
I had data in my old database, but I cannot see my posts, pages, users, etc., on my SQLite installation.
The SQLite implementation does not provide a method for migrating data between databases. Since this proposal is intended for integration into WordPress Core, adherence to WordPress Core principles is essential. Data migration is outside the Core’s responsibilities and is more suited for plugins. Your data is safe in your previous database, and you can regain access to it by disabling the SQLite module.
Once SQLite is integrated into Core, migration and backup plugins will offer support for it.
Will this function if there is already a db.php file in my wp-content folder?
Regrettably, no. If there is an existing db.php file in your wp-content folder, you will be unable to test SQLite on your site.
To determine if a db.php file from another plugin is present, you can navigate from your dashboard to the plugins screen and check the Drop-in tab.
It’s important to note that this limitation exists solely because the implementation is currently in a plugin, necessitating the use of the drop-in file. This issue will be resolved once SQLite becomes a part of Core.
Historical/Implementation Details
The SQLite implementation’s code is derived from https://github.com/aaemnnosttv/wp-sqlite-db/blob/master/src/db.php, originally by Evan Mattson, which is a fork of the sqlite-integration plugin created by Kojima Toshiyasu (removed from repository). We then refactored this code, applied coding standards, and developed an integration with the Performance Lab plugin.
The SQLite code in use has been operational for many years and has undergone extensive testing. We decided to build upon a proven solution rather than starting anew to avoid reworking many issues that have already been resolved in the existing implementation.