The directions below will provide simple instructions on changing the prefix to your WordPress blog’s MySQL database from wp_ to whatever you choose. Its a good idea to change this prefix to prevent zero-day SQL injection attacks from being performed against your WordPress installation since your database tables will be known to everyone if you use the default prefix. So follow the below directions to make the change that should only cause minimal downtime if the steps are followed properly.

  1. MySQL Database Backup:Use the CLI or backup your database from phpMyAdmin. If using phpMyAdmin use the export feature to export a SQL version of your database and download it to the PC you are working on. Your backup should be something similar to mydb_DATE.sql.
  2. Backup MySQL Database Backup:Make sure to first copy a backup of the database backup so you should now have two files named something like mydb_DATE.sql and mydb_DATE.sql.bak.
  3. Replace wp_ Table Prefix:Now open the .sql file in a text editor that has a find and replace capability. Use this to search and replace wp_ with whatever prefix you want to change to. Depending on how big your database is will depend on how long this will take and how many replacements will be made.
  4. Drop Tables:Drop all of the tables currently in your database. This can be done through phpMyAdmin as well by clicking on the database, then clicking the “Check All” link at at the bottom of the page, choose the Drop action, and then confirm dropping all of the tables which will be plus or minus 30 MySQL database tables.
  5. Zip Modified Database Backup:Use a compression application to zip, gzip, or bzip the modified database backup. Compressing this file will make it much smaller to upload as many servers have a Max PHP Upload setting.
  6. Import Modified MySQL Backup: Now click on the Import tab in the top of phpMyAdmin which will accept zip, gzip, bzip, or regular SQL files. Click the Browse button and navigate to the compressed modified database backup. Click the go button to begin the backup. This may take awhile as it not only has to upload the file but it also has to process all of the SQL statements.
  7. Modify WP Config File:Now open the wp-config.php file (located in the WordPress root directory) and change the $table_prefix value from wp_ to whatever you modified the prefix to in step 3.
  8. Verify and Test:You should now be able to login and test your WordPress blog. One thing to verify is that all plugins are working properly as there is always the chance that modifying the table prefix caused an issue where you may have to deactivate and/or activate only the plugin.

Again it is extremely important to make this modification from the default WordPress table prefix to prevent possible zero-day SQL injection attacks. These zero-day SQL injection vulnerabilities are attacks that have yet to be discovered and would leave your blog open to attack until a patch is written and then installed on your WordPress installation.

Tags: , , , , , , , , ,
8 Responses to “Change the Table Prefix of WordPress Blog MySQL Database from wp_”
  1. PiterKokoniz says:

    Hello !!!! :)
    I am Piter Kokoniz. Just want to tell, that I like your blog very much!
    And want to ask you: will you continue to post in this blog in future?
    Sorry for my bad english:)
    Thank you!
    Piter Kokoniz, from Latvia


    alex Reply:

    Hello Piter,

    Thanks so much for the feedback for the blog. I will b e posting in the future. I typically try to post one article a day in the blog and at this point I plan to continue to do that into the future.

    Alex from Louisville, KY, USA :)

    PS. Your English is actually really good. Much better than my Latvian/Russian. :)


  2. Proxy Kid says:

    My teacher talked about this in school last week.


  3. John says:


    I followed the above instructions. But when I try to import my modified sql file I get

    ‘#1007 – Can’t create database ‘acoustj0_wrdp1′; database exists ‘

    Any suggestions would be greatly appreciated.



    alex Reply:

    Hello John,

    It looks like however you are backing up your MySQL database it is including the “create database” text. You can either remove this manually or make sure when backing up the database to not have it include creating the database. That should resolve your problem.


  4. Filme Runterladen says:

    Damn, that sound’s so easy if you think about it.


  5. alex says:


    what do you recommend using if one’s mysql database is too large for phpMyAdmin to handle importing? mysql database is 307 mb as a .gz file.

    also, if i change the table prefixes and upload, other than checking plugins and wp-config file settings, i shouldn’t have to make any additional changes in mysql database settings?
    everything should work properly?




    alex Reply:

    Hello alex,

    You can either modify your php.ini file to allow for larger uploads or you can copy the database to the server using scp or sftp and then import it using the MySQL command line. You are correct… everything should work properly.



Leave a Reply

*Type the letter/number combination in the abvoe field before clicking submit.