So there you are, minding your own business and creating a new WordPress site using Laragon. You’re about to finish the setup when suddenly… BAAMM!! You’re greeted with a page full of
WordPress database error: [Table '<name>' already exists]. What happened? You’ve fucked up! That’s what happened. But no need to worry, 🤗 I’m here to help you out. In this article, I’ll show you why you’ve got this error, how to solve the Table already exists error in Laragon as well as how you can prevent this from happening again in the future.
Oh, and if you’re reading this article, not knowing how to set up a WordPress site with Laragon or don’t even know what Laragon is, check out my article on why it’s my favorite WordPress development setup so far. Although, I’m not sure why you’re reading this if that’s the case… ಠ_ಠ
The origin of the error
So what causes this error to appear? As the message of the error implies, a database with the same name already exists. In other words, you’ve failed to properly delete a previous website and its database of the same name. Yet, when you check the specific database in HeidiSQL, all those tables mentioned in the errors don’t even exist. It’s all empty! Strange… well, you’ve unfortunately got a case of Schrödinger’s table. 😫 And no, trying to drop the database table now won’t help you out.
If you’re like me, you might have attempted to delete your WordPress site by removing
data/mysql/example and perhaps even
etc\apache2\sites-enabled\auto.example.test.conf. While not completely wrong, there was one important step you’ve forgotten to do! 😬
However, before I get into what the correct website deletion process is, let me first show you how to solve this pesky problem.
Solving the error
Alright, so for all you non-developers out there reading this, it’s gonna get a bit techy. 👩💻 So make sure you read these steps carefully, then you’ll be just fine. For the developers… well, this shouldn’t look too foreign for you. Let’s get started, shall we?
First of all, make sure any folders and files related to this name are deleted. Is that the case? Good… Make sure your Laragon server is turned on! Is that also the case? Very gooood… Now access Laragon’s built-in terminal. You can do that either through the dashboard, or invoke it with the command
Ctrl + Alt + T or even with
Ctrl + ` if it’s already been opened before.
Create a backup
Next, we want to back up all our databases into a
.sql file. To do this, execute the following command in your terminal:
mysqldump.exe -u root -p --all-databases > C:\laragon\tmp\alldb.sql.
This command essentially tells your computer to run an
.exe program 🤖 on all databases by using the database credentials immediately following
-u (for user) and
-p (for password). If you’ve not meddled with the default database user who is responsible for accessing your Laragon database, then its username is
root with no password. If you’ve changed this, make sure to change these details in the command accordingly! That which follows
> is the output of our command, specifically the location and name of our backup file. Likewise, if your
\tmp folder is located elsewhere, change this!
Rename your data directory
After you’ve completed the backup, head over to
C:\laragon and rename your
data folder to
data.bak. This will only work once your Laragon server is turned off. 💤
So yep… this was a pretty short section. But hey, I’m trying to make this as structured as possible. 🤷♀️
Restore all the data
Alright, now start up your Laragon server again! 🙄 Doing this will automatically create a new
C:\laragon\data folder. This time, we want to restore all our databases from the
.sql backup that we previously created. In the Laragon terminal, run the command
mysql -u root -p < C:\laragon\tmp\alldb.sql.
Once again, this command tells your computer to run
mysql using the user credentials following
-p. However, instead of creating an output this time as we did before, we’re taking an input for our database restoration. Or to be more precise, we’re importing a
.sql file, hence the inverse
After completing this final step, you can go ahead and recreate that WordPress site of yours. And behold! The glory of your hard work… 😍
How to delete a WordPress site in Laragon
Okay, now that we’ve got that pesky problem out of the way, what’s the proper procedure to delete a WordPress site in Laragon? It’s simple, really… 😋 Do almost the same things as mentioned at the start of this article, except for one key difference: drop/delete your site’s database through your database manager HeidiSQL rather than deleting the folder itself.
How do you do this? Once again, you can access your database through the Laragon dashboard by clicking on the Database button. Then, double click on Laragon under the column Session name on the left side. You should now be presented with a list of all your databases. From here, simply right click on the relevant database and choose Drop… 💀 There you go!
From here on, you can delete the usual files and folders. However, now you should not be getting a case of Schrödinger’s table.
Did you find what you came for? Want me to cover something else? Let me know in the comments below! Share, if you liked this post!