Changing WordPress database prefix for mySQL in a maximum of 15 words.

thay đổi tiền tố wordpress

To change the WordPress table prefix in a MySQL database, use the provided SQL query by updating the database name, old prefix, and new prefix. The query will generate multiple SQL queries to rename all tables. After renaming, replace values in _usermeta and _options tables using provided queries. Remember to update values again. Following these steps will successfully change the WordPress table prefix in the MySQL database. For more in-depth knowledge, refer to the article mentioned. Subsequently, explore the basic WordPress section for further learning. Follow the fan page for the latest updates and articles from Hocwordpress Group.


How to Change WordPress Table Prefix in MySQL Database

If you’re looking to change the WordPress table prefix of your database on an existing site, you can easily do so using a SQL query. It’s essential to customize the query to match your specific requirements.

SQL Query

SET @database  = "yourdatabasename";
SET @oldprefix = "oldprefix_";
SET @newprefix = "newprefix_";

SELECT
    concat(
        "RENAME TABLE ",
        TABLE_NAME,
        " TO ",
        replace(TABLE_NAME, @oldprefix, @newprefix),
        ';'
    ) AS SQL
FROM information_schema.TABLES WHERE TABLE_SCHEMA = @database;

This SQL query will generate individual queries to rename all tables from the old prefix to the new prefix. Copy and execute these queries to apply the changes effectively.

After renaming the tables, remember to update certain values in the tables, particularly in *_usermeta and *_options, using the following queries.

Updating *_usermeta

UPDATE `newprefix_usermeta`
SET meta_key = REPLACE(meta_key, 'oldprefix_', 'newprefix_')
WHERE meta_key LIKE 'oldprefix_%';

Updating *_options

UPDATE `newprefix_options` 
SET option_value = REPLACE(option_value, 'oldprefix_', 'newprefix_') 
WHERE option_name LIKE 'oldprefix_%';

By executing these queries, you’ll complete the process of changing the WordPress table prefix in your MySQL database successfully. For further detailed information, you can refer to this article.

See also  Simple and Fast Steps to Create Categories in WordPress

Epilogue

Congratulations on completing the WordPress table prefix change in your MySQL database. Feel free to delve into more WordPress topics to expand your knowledge.

Stay updated with the latest articles by following our fan page: Hocwordpress Group.

Rate this article: 4.7 (3 votes)

Rate this post

Related posts