测试背景:
由于起初安装magento的时候没有添加数据库表前缀,现在想给所有的数据库表添加前缀。
测试步骤:
1.写批处理语句change_prefix.sql,内容如下:
delimiter // DROP procedure IF EXISTS change_prefix // CREATE procedure change_prefix(IN oldpre VARCHAR(200), IN newpre VARCHAR(200), IN dbname VARCHAR(200)) begin declare done INT DEFAULT 0; declare oldname VARCHAR(200); declare cur CURSOR FOR SELECT table_name FROM information_schema.TABLES WHERE table_schema= dbname AND table_name LIKE concat(oldpre,'%'); declare continue handler FOR NOT found SET done = 1; open cur; repeat fetch cur INTO oldname; IF NOT done then SET @newname = concat(newpre, trim(LEADING oldpre FROM oldname)); SET @sql = concat('rename table ',oldname,' to ',@newname); prepare tmpstmt FROM @sql ; execute tmpstmt; deallocate prepare tmpstmt; end IF; until done end repeat; close cur; end // delimiter ; |
2.命令行登录mysql执行以下操作:
-- use magento; -- show tables; -- source /home/change_prefix.sql; -- -- call change_prefix('', 'mdb_', 'magento'); -- -- show tables; -- drop procedure if exists change_prefix; -- |
参数说明:
第一个参数是:原数据库表前缀,留空表示无前缀
第二个参数是:你要修改的新前缀,留空表示取消所有表前缀
第三个参数是:你的数据库名
call change_prefix('oldprefix_','newprefix_', 'DB_NAME');
3.重新安装magento,数据库还用magento,用户信息不变,记得填写数据库表前缀,要写成你刚才添加的那个前缀。
参考:http://www.jzbk.org/blog/2011-10/547.html
本文出自 “Centi.Linux” 博客,请务必保留此出处http://centilinux.blog.51cto.com/1454781/781357