搭建 WordPress 的时候,忘记修改数据库前缀名称了,默认为 wp_ ,我需要将 wp_ 改成 test_ ;
-- 生成组装替换命令 -- 将数据库 test_com 以 wp_ 开头的表名 , 替换为 test_ 开头 SELECT CONCAT( 'ALTER TABLE ', t.TABLE_NAME, -- 表名 ' RENAME TO ', REPLACE (t.TABLE_NAME , -- 表名 'wp_', -- 要替换的表名前缀 'test_') -- 替换成 test_ 表名前缀 , ';') FROM information_schema.TABLES t WHERE -- 匹配表,以 wp_ 开头的表 t.TABLE_NAME LIKE 'wp_%' AND -- 数据库名称 t.TABLE_SCHEMA = 'test_com';
会生成如下的 SQL 语句,拿着语句执行 SQL 就可以了
ALTER TABLE wp_comments RENAME TO test_comments; ALTER TABLE wp_links RENAME TO test_links; ALTER TABLE wp_options RENAME TO test_options; ALTER TABLE wp_postmeta RENAME TO test_postmeta; ALTER TABLE wp_posts RENAME TO test_posts;
以上替换是 MySql 的方法。(通用方法)
1. 修改 wp-config.php 文件中的 WordPress 数据库表前缀
默认为
$table_prefix = 'wp_';
改至
$table_prefix = 'test_';
2. 修改数据库 test_options
表中的 option_name
字段含有 wp_
UPDATE test_options io SET io.option_name = REPLACE( option_name, 'wp_', 'test_' ) WHERE io.option_name LIKE 'wp_%';
2. 修改数据库 test_usermeta
表中的 meta_key
字段含有 wp_
UPDATE test_usermeta iu SET iu.meta_key = REPLACE( meta_key, 'wp_', 'test_' ) WHERE iu.meta_key LIKE 'wp_%';