Undrar du hur du ändrar prefixet för WordPress database för din website?
Genom att Changed prefixet för databasen kan du skydda din website mot SQL-injektioner och andra attacker från hackare på nätet. Det kan vara ett viktigt steg mot att förbättra WordPress säkerhet.
I den här tutorialen visar vi hur du ändrar prefixet för WordPress database för att förbättra säkerheten.
Varför ska du ändra prefixet för WordPress Database?
WordPress Database är som en hjärna för hela din WordPress website eftersom all information och alla filer lagras där.
Detta gör databasen till ett favoritmål för hackare. Spammare och hackare kan runka automatiserade koder för SQL-injektioner och ta sig in i din WordPress Database.
Tyvärr är det många som glömmer att ändra prefixet för databasen när de installerar WordPress. Detta gör det lättare för hackare att planera en massattack genom att rikta in sig på standardprefixet wp_.
Det enklaste sättet att skydda din WordPress-databas är genom att ändra databasprefixet, vilket är väldigt enkelt att göra på en site som du håller på att sätta upp.
Det krävs några extra steg för att ändra WordPress-databasprefixet på rätt sätt för din etablerade site utan att helt förstöra det. Med detta sagt kommer vi att visa dig hur du ändrar WordPress databasprefix och förbättrar din WordPress säkerhet.
Video Tutorial
Om du inte gillar videoklippet eller behöver fler instruktioner är det bara att fortsätta läsa.
Så här ändrar du prefixet för WordPress Database
Vi rekommenderar att du säkerhetskopierar din WordPress database innan du gör något av det som föreslås i denna tutorial. Det är också viktigt att hålla dagliga backups av din WordPress website med hjälp av ett plugin som gillar Duplicator.
Vi rekommenderar också att du redirectar dina visitors till en tillfällig maintenance page medan du ändrar prefixet i databasen. Annars kan du orsaka en dålig användarupplevelse för besökarna på din website.
Hur man ändrar tabellprefix i wp-config.php
Först måste du ansluta till din website med FTP eller appen File Manager på ditt WordPress webbhotell account.
You then need to open your wp-config.php file, which is located in your WordPress root directory. Här kan du ändra tabellprefixraden från wp_ till något annat som gillar detta wp_a123456_
Så raden skulle se ut så här:
$table_prefix = 'wp_a123456_';
Note: Du kan bara ändra tabellprefixet med siffror, bokstäver och understreck.
Ändra alla namn på Database Table
Därefter måste du ansluta till din database med hjälp av phpMyAdmin tool. Om ditt webbhotell använder cPanel dashpanelen, kan du enkelt hitta phpMyAdmin där.
Det finns totalt 11 standard WordPress tabeller, så att ändra dem manuellt skulle vara en smärta.
Istället ska du klicka på tabben ”SQL” högst upp.
Följaktligen kan du enter följande SQL sökning:
RENAME table `wp_commentmeta` TO `wp_a123456_commentmeta`;
RENAME table `wp_comments` TO `wp_a123456_comments`;
RENAME table `wp_links` TO `wp_a123456_links`;
RENAME table `wp_options` TO `wp_a123456_options`;
RENAME table `wp_postmeta` TO `wp_a123456_postmeta`;
RENAME table `wp_posts` TO `wp_a123456_posts`;
RENAME table `wp_terms` TO `wp_a123456_terms`;
RENAME table `wp_termmeta` TO `wp_a123456_termmeta`;
RENAME table `wp_term_relationships` TO `wp_a123456_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_a123456_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_a123456_usermeta`;
RENAME table `wp_users` TO `wp_a123456_users`;
Kom ihåg att ändra prefixet för databasen till det som du valde när du editerade filen wp-config.php.
Du kan också behöva lägga till rader för andra tillägg som lägger till sina egna tabeller i WordPress database. Tanken är att du ändrar allas tabellprefix till det som du vill ha.
Tabellen över alternativ
Vi måste sedan searcha i tabellen Options
efter andra fält som använder wp_ som prefix så att vi kan ersätta dem.
För att påskynda processen kan du använda den här sökningen:
SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE '%wp_%'
Detta kommer att ge många resultat, och du måste gå igenom dem en efter en för att ändra dessa rader och deras prefix.
UserMeta-tabell
Därefter måste vi searcha usermeta
efter alla fält som använder wp_ som prefix, så att vi kan ersätta det.
Du kan använda den här SQL-sökningen för det:
SELECT * FROM `wp_a123456_usermeta` WHERE `meta_key` LIKE '%wp_%'
Antalet entries kan variera beroende på hur många WordPress tillägg du använder på din website. Byt bara ut allt som har wp_ till det nya prefixet.
You are now ready to test your site. Om du följde stegen ovan bör allt fungera bra.
Vi rekommenderar att du gör en new backup av din database för säkerhets skull.
Vi hoppas att den här artikeln hjälpte dig att lära dig hur du ändrar prefixet för WordPress database. You may also like to see our guide on how to optimize your WordPress database and our expert picks of the best WordPress database plugins.
Syed Balkhi says
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Moinuddin Waheed says
This is an eye opener for wordpress security.
I never felt the need to change the database prefix for its simplicity and never knew that leaving it as it is can be dangerous.
I think most of the beginners leave database prefix as it is and never change it.
I will definitely keep this in mind while installing every new wordpress website.
Mrteesurez says
Yes most beginner bloggers including me, leave it without changing because we didn’t know the implications therein. It is best and easier to change during new WP installation while is challenging for an established blog.
Dayo Olobayo says
You’re right Moinuddin. Many beginners (myself included) often overlook this step. The ”default” nature of the prefix can lull one into a false sense of security. Changing it adds an extra hurdle for attackers using automated scripts. It’s a simple security measure that can make a big difference.
mohadese esmaeeli says
Hello. Changing the prefix of WordPress tables is very, very important because this prefix is the default, and most people don’t change it, making it susceptible to testing by any hacker. So, it makes sense to alter it, and I recommend this to all my friends. If we change the prefix during the WordPress installation, it’s much better. However, even after installation, it is possible to change the table prefix.
Ka Khaliq says
Hi there,
I’m referring to this article to update my WordPress website database prefix.
I have a confusion about updating the Options and Usermeta tables. Upon running the respective SQL queries, the results obtained, also contains some rows something like transient_wp_cloudflare OR dismissed_wp_pointers OR tlwp_feedback_data OR wpseo_social etc.
So do I need to update such rows too where wp_ is present in the middle/end OR do I just need to update rows that has the wp_ prefix at the start like wp_page_for_privacy_policy etc.
I understand that by prefix means, something at the start but still want to solve this confusion.
WPBeginner Support says
No, you would want to leave those tables as they are as those are used by plugins and other tools that are looking for those specific titles.
Administratör
Eka says
you save my time, thanks alot bro.![:D](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)
i do test password and the problem has been detect
thanks !
WPBeginner Support says
Glad our guide was helpful
Administratör
Barry Richardson says
A plugin developer told me that you cannot have a WordPress blog without a database prefix. This is very confusing because I have had an active WordPress blog for 5 years – and it has no database prefix. So, can you have a WordPress site without a database prefix?
WPBeginner Support says
WordPress has a database prefix by default without you needing to make any changes, this is a way to customize the prefix.
Administratör
Emily says
Hi there, I was following another tutorial to look at the database files and noticed mine have names like ”wphy_users” … is this possibly an extension of the thing described here, just without the _ before?
Look forward to your reply!
WPBeginner Support says
Correct, from the sound of it your database was created with a different prefix
Administratör
Izzy says
Hi, I changed my table prefix names ia while a go. I found out there where some new maps added with the old name + the main folder (database I think) also has the old name. Now I also found out my folders already HAD a different name than the standard ”wp” prefix name, so the change wasn’t even needed in the first place. The only thing now is that half of the tables has 1 certain name and the other ones have another name. Because everything works fine now I don’t want to change things again, but my only question now is: is it a problem that the tables have different names? Do they all need to be named the same, or does it not matter?
WPBeginner Support says
The extra tables may have been created by a plugin, we would recommend your site using the same prefix for all of your content.
Administratör
Akhilesh says
I am multi domain hosting. at the time of installation of WP what have to put in table prefix (as wp_ written by default.)??
Please suggest me as early as possible…
WPBeginner Support says
You would choose what you want the prefix to be if you’re changing your site’s database prefix
Administratör
Mainak Ghosh says
After changing database prefix i am getting ”Sorry, you are not allowed to access this page” this error when i visit WordPress admin dashboard.
WPBeginner Support says
You may want to ensure you updated all of the links in your tables and you may want to check your wp-config file for another location. To see if it is more than one error you could enable wp debug: https://www.wpbeginner.com/wp-tutorials/how-to-set-up-wordpress-error-logs-in-wp-config/
Administratör
Kid Max says
Hi, I’m using wordpess multisite. I want to use home site’s database prefix and folder for media attachment for all of subsite including home site. Any idea?
WPBeginner Support says
You could upload your images to the home site’s media library and embed the images on your subsites to do something like that.
Administratör
Kid Max says
I know about that, but featured images not support for that, so I want to use home site’s media database prefix for all site.
WPBeginner Support says
Sadly, at the moment we don’t have a recommended method for that.
Mike says
I tried it and then I couldn’t login. Probably because I have a security plugin.
If I disable and delete all my plugins and just leave my installation with the core WP, and then I make the change, would that probably eliminate the need to change anything in usermeta or the options tables? i.e. Would that probably be the safest way to make the table change and not break anything.
Then, I’ll just re-install my plugins.
Mishel says
According to this article, Changing the WordPress table prefix does absolutely nothing to enhance the site security.
Even if we have changed the table prefix, a hacker can find the table prefix by running this code:
SELECT DISTINCT SUBSTRING(`TABLE_NAME` FROM 1 FOR ( LENGTH(`TABLE_NAME`)-8 ) )
2
FROM information_schema.TABLES WHERE
3
`TABLE_NAME` LIKE ’%postmeta’;
WPBeginner Support says
Hi Mishel,
We don’t agree with that. Every security step that obscures something can be uncovered by a experienced hacker. These steps just add a difficulty layer to make your overall security harder to crack. Changing table prefix certainly has no downside to it and if it can block some automated and obvious hacking attempts, then its totally worth it.
Administratör
Sayeed says
Yes I agree.
Daniel says
Just what I was looking for. Thanks.
Mehdi says
The queries in both wp_options and wp_usermeta return datas that is contained wp should I rename them too?
ex: wpseo_title, _yoast_wpseo_
rado says
I made really silly mistake, in my wp-config file i assign the variable $table-prefix without the underscore at the end. Something like ”wp_12345”, it should be ”wp_12345_”.
Molly says
this broke my files, none of my files are accessible on the local or live sites, thankfully this is all learning and a test site, but what went wrong?
Josch says
Works fine, thank you very much! Except: I get the following warning in the backend after changing prefix. Tried it two times:
Warning: Cannot modify header information – headers already sent by (output started at /myurl/wp-config.php:1) in /myurl/wp-includes/option.php on line 837
Warning: Cannot modify header information – headers already sent by (output started at /myurl/wp-config.php:1) in /myurl/wp-includes/option.php on line 838
Can you help me?
WPBeginner Support says
Hi Josch,
This error can be caused by an empty space or an extra line at the end of wp-config.php file. Deleting it can solve the issue.
Administratör
Mehdi says
Hi, thank you for your article. I have a question about that. If you have some plugins which are installed in your wordpress, is this method that you mentioned above the same? or maybe we need to other things to complete this step?
I appreciate if you guide me about that because I have more than 20 install plugin in my wordpress sit.
Thank you for your help
Asterix says
Won’t I have issues when updating plugins etc in the future?
I tried to use iThemes Security built in advanced features for this, but got the error: An ”invalid format” error prevented the request from completing as expected. The format of data returned could not be recognized. This could be due to a plugin/theme conflict or a server configuration issue.
So I am not sure if I dare to do this manually either…
Joe says
Hello Team
thanks for sharing this.
All steps went well except for the last one: UserMeta Table.
MySql doesn’t let me change the prefix for it.
That’s the error message I get:
#1054 – Unknown column ’wp_new_usermeta.umeta_id’ in ’where clause’
Please, any advise?
Many thanks,
Joe
Shivam Pandey says
How to change the database prefix while installing WordPress.
Vipul Parekh says
There’s an option it asked to enter db prefix while installation. so you can give prefix whatever you wish to!!
Tom B. says
Is it necessary to still include the”wp_” as part of the new prefix I want to create? Can I just use any alpha numeric string to reduce the chance of any type of hack?
Thanks,
Tom
WPBeginner Support says
Yes, you can use alpha-numeric string.
Administratör
Chad Mowery says
Nice article. I think the query on the Options and UserMeta table will throw off less savvy individuals. Not sure how but it would help if you could provide more detail on those steps.
I followed the guide and have successfully changed my DB table prefix!
blade says
This does not add really any kind of security.
If I can inject SQL, I can query against information_schema.tables and get info about tables, whatever fancy prefix you put in front of names
thomas says
very true. a good htaaccess will block sql injections too. on top of that, my wordpress install only gives full database access to very select users by assigning those credentials based on certain things gathered long before a db connection. everybody else gets the very very basic access.
i also stopped most hacking attempts cold by hiding the wpzlogin.php and further password protecting access to wp admin in cpanel. it takes a login just to get to the wp login page.
John says
@Shivi
This is all you need to do to change table.prefix ? even when live?
shivi says
Hi , Nice article ! Thought of simplifying replacing table prefix.
In Phpmyadmin once u select the database, you can see the list of tables.
1. Enable the checkbox check all
2. select Replace table prefix in the dropdown ’with selected’
3. Enter the existing prefix in from option: ’wp_’ as mentioned in the article.
4. Enter the new prefix in to option: ’wp_a123456_’ as mentioned in the article.
5. Click submit
This helps to change table prefix for all tables including that of the plugin.
You can check these articles if you need support on dehack your site
john says
So…. @SHIVI
All I need to do, to change the table.prefix is go into my config.file change the prefix and then proceed to your steps 1-5 and the table.prefix will be changed everywhere (plugins etc..)
And that’s it?
Dana Nourie says
Sweet! This was great.
Matt Boden says
You’ll still need to manually update the prefix on the options and usermeta tables.
Fahim says
Should i run Sql for every table? i mean i have 15 table. or only change two tables you described will fix the problem.
WPBeginner Support says
All tables. You would want to change table prefix from all your existing WordPress tables.
Administratör
Alph says
Hi guys,
Thanks for these instructions. They helped me resolve my uppercase issues.
As a beginner, some guidance as to the how to change the table names manually would have been appreciated. I would have felt more comfortable doing it that way.
Also, for a beginner like me, some instruction on how to make the changes in the Options and Usermeta tables would been helpful.
Thanks again. Could not have done it without you!
Chris A says
Thanks for the instruction. I needed to remove an UPPER case letter from a prefix and this showed that exact records I needed to touch!
TIP: with phpMyAdmin you can check all records at the bottom and select ’replace table prefix’ this will bring up a standard replace box with ’from’ and ’to’ values.
It will also save a lot of typing in step one – especially if it’s a large database.
Prabhakar says
You made it !
Thanks
Igor says
Hi guys,
when I made these changes it don’t give me to sign in as current user but it tells me to install wordpress again…
Igor
WPBeginner Support says
This usually happens when the database you connected to is empty. Please recheck your database name.
Administratör
Alan P says
wp_termmeta is missing from the list of tables to rename.
WPBeginner Support says
Thank you for notifying us. We have updated the article.
Administratör
Rick says
My SQl DB have no table prefix so got error sometimes on wordpress Wpconfig.php without $table_prefix = ”;.
how to add table prefix,
when i try to add in config file and rename all table with same prefix
and login in to wp got error ”you don’t have permission to access”
Sameer Panda says
Worked as a charm, thanks for sharing.
Dave van Hoorn says
Update the SQL for renaming the prefixes please. WordPress adds the ’wp_termmeta’ table now. It’s included in the SQL below.
RENAME table `wp_commentmeta` TO `wp_yoursitename_commentmeta`;
RENAME table `wp_comments` TO `wp_yoursitename_comments`;
RENAME table `wp_links` TO `wp_yoursitename_links`;
RENAME table `wp_options` TO `wp_yoursitename_options`;
RENAME table `wp_postmeta` TO `wp_yoursitename_postmeta`;
RENAME table `wp_posts` TO `wp_yoursitename_posts`;
RENAME table `wp_termmeta` TO `wp_yoursitename_termmeta`;
RENAME table `wp_terms` TO `wp_yoursitename_terms`;
RENAME table `wp_term_relationships` TO `wp_yoursitename_term_relationships`;
RENAME table `wp_term_taxonomy` TO `wp_yoursitename_term_taxonomy`;
RENAME table `wp_usermeta` TO `wp_yoursitename_usermeta`;
RENAME table `wp_users` TO `wp_yoursitename_users`;
Prabhudatta Sahoo says
When I am renaming my tables in the database all the images in the gallery are going away, I do not understand the reason. Could anyone please help me fixing this issue?
Terry Thorson says
This issue will occur if you do not update the serialized data strings (used for your gallery images) correctly in the database. A good way to do this is to use the plugin WP Migrate DB. There is an excellent tutorial for this on Lynda.com (although be sure to use the same prefix for your target database as your source database).
I learned this the hard way. Trying to start afresh, I discovered my backup was faulty as well. Luckily my webhost had an older backup I could use to restart my migration. WP Migrate DB did the trick.
Cameron Jones says
I can’t find any fields in the _usermeta or _options tables that would require updating. Unless they are specifically referencing a table, they shouldn’t need to be updated. It’s a table prefix, not a variable prefix.
Cameron Jones says
Actually, I stand corrected. There are a couple that will be part of a default WordPress install:
In prefix_options
prefix_user_roles
In prefix_usermeta
prefix_capabilities
prefix_user_level
prefix_dashboard_quick_press_last_post_id
prefix_user-settings
prefix_user-settings-time
You should be careful regarding updating any other fields. Plugins may either use the defined prefix or `wp_` as a prefix. Always make a backup and test on a dev or staging environment.
kapil says
hi,
i have a query. assume that i have changed all my prefix from wp_something to some other name. these changes will be done to the existing fields in the database only. but wont the codes in my wordpress .php files remain the same??? so next time for any new user registration or some other registration, the entities will again be saved as wp_something as the main code in the .php files remains unchanged… ???
thanks….
tech says
UPDATE `wp_a123456_options` SET `option_name`=REPLACE(`option_name`,’wp_’,’wp_a123456_’) WHERE `option_name` LIKE ‘%wp_%’;
UPDATE `wp_a123456_usermeta` SET `meta_key`=REPLACE(`meta_key`,’wp_’,’wp_a123456_’) WHERE `meta_key` LIKE ‘%wp_%’;
I do changes but after doing this i again run following query it shows prefix not changed
SELECT * FROM `wp_a123456_options` WHERE `option_name` LIKE ’%wp_%’
Wiem says
Thank you for the queries
Nathan WHite says
This post and the responses to the comments leaves out a very important component. Does the table need to begin with wp_ ?
Coming upon another discussion in wordpress.org indicated that it indeed did not need to. It would have helped me if this question was answered by the moderator.
Also, dismissed_wp_pointers questions were not clearly answered. I changed mine.
Clare Wood says
Hi guys,
I followed these steps, now when I try to see the back-end or front-end of my site I get this:
ERROR: $table_prefix in wp-config.php can only contain numbers, letters, and underscores.
I’m positive I only have lowercase letters and an underscore as my table prefix.
Any ideas? The site is on localhost.
Cheers.
Paul says
Fantastic and logically prepared article on Wp security.
Thomas says
Thanx a bunch! I tried to restore my old database, but to no avail. Then I figured out that my new database prefix was different from old. Made all that you recommended and vuala!
Divyesh says
Thanks a Lot!!!
It worked like a charm
Nikhil says
I am getting this error…….”You do not have sufficient permissions to access this page” after implementing above procedure…..how to solve it?????
Saz says
These instructions have been followed but now role assignment for new users has disappeared…
Tom says
Thanks for a great tips .
I have a question.
Do I need to change ”wp_ ….” used in post_meta table as well?
johnny says
or this plugin http://wordpress.org/plugins/db-prefix-change/
savagemike says
For the wp_options and wp_usermeta tables, why not dump the database and use sed to replace ”wp_” with the new prefix? Example:
sed -i ’s/wp_/wp_1234/g’ > filename.sql
Then, simply import the modified dump. Easier and faster than changing cells one-by-one.
gcreator says
Attacker can simple use ’%wp_%’
I mean that is not fully secure at all…
because he knows the table names that wordpress generates he can simply use ’_%users’ for wp_anything_users OR ’_%posts’ for ’wp_anything_posts’ ..etc…
Jim says
gcreator…
For 99% of the attacks against WP databases, the skiddies are using pre-built tools and default settings. This gets you out of their crosshairs.
if you are under focused attack then yeah, simple obfuscation will only slow them down, not completely protect you.