Magento更改数据库表前缀

问题描述:

我意外地为表前缀提供了没有下划线的Magento安装。有没有可以自动更改的选项?我不喜欢用手改变337桌:-)Magento更改数据库表前缀

我试过this解决方案,但似乎没有工作。

迈克尔

+0

这个PHP脚本为你所做的选择答案的工作?什么版本的Magento? – Dan 2015-03-06 17:13:19

您可以创建SQL这个选择要重命名的所有表:

SELECT 'rename table '||table_name||' to '||'newprefix'||table_name||';' 
FROM information_schema.tables 
+0

或者使用'SELECT CONCAT('rename table',table_name''to','newprefix_',table_name,';')FROM information_schema.tables'获得[更好的兼容性](http://*.com/a/8212239/1402846)。 – Pang 2014-09-24 03:02:50

<?php 
$database_host="localhost"; 
$database_user="root"; 
$database_password=""; 
$magento_database="test1"; 
$table_prefix="magtest_"; 
?> 
<?php 
$db=mysql_connect($database_host,$database_user,$database_password); 
mysql_select_db($magento_database); 
$query="SHOW TABLES"; 
$result=mysql_query($query) or die('Err'); 
while($row=mysql_fetch_array($result)){$old_table=$row[0]; 
if(preg_match('/'.$table_prefix.'/',$old_table)){echo"Table $old_table already done<br/>\n";continue;} 
$new_table=$table_prefix.$old_table;echo"Renaming $old_table to $new_table<br/>\n"; 
$query="RENAME TABLE `$old_table`  TO `$new_table`";mysql_query($query);} 
?> 

步骤:

  1. 采取数据库备份。
  2. 创建一个文件名为“rename_table_prefix.php”并放置在根目录下。
  3. 将上面的脚本粘贴在其中。
  4. 运行文件http:www.domain.com/magento/rename_table_prefix.php
  5. 所有的表格都将被重命名。
  6. 到应用程序的/ etc/local.xml中
  7. 修改下面一行,因为它是
  8. 大功告成。

我跑了变化Magento的数据库表前缀

// mege_rename_table_prefix.php 
//New Prefix Name 
$table_prefix = "test_"; 
//Magento Database Backup php script 
    error_reporting(E_ALL^E_NOTICE); 
    ini_set('display_errors', 1); 
    ini_set('memory_limit', '1512M'); 
    // Get Magento Application 
    require_once 'app/Mage.php'; 
    Mage::app(); 
    // Mage::app('default'); 
    //Mage::app('main'); 
    // get Magento config 
    $config = Mage::getConfig()->getResourceConnectionConfig("default_setup"); 
    $dbinfo = array(
     "host" => $config->host, 
     "user" => $config->username, 
     "pass" => $config->password, 
     "dbname" => $config->dbname 
    ); 
    // Database Config 
    $db_host = $dbinfo["host"]; 
    $db_user = $dbinfo["user"]; 
    $db_pass = $dbinfo["pass"]; 
    $db_name = $dbinfo["dbname"]; 
//conect db 
$db = mysql_connect($db_host, $db_user, $db_pass); 
mysql_select_db($db_name); 
$query = "SHOW TABLES"; 
$result = mysql_query($query) or die('Err'); 
while($row = mysql_fetch_array($result)) { 
    $old_table = $row[0]; 
    if(preg_match('/'.$table_prefix.'/', $old_table)) { 
     echo "Table $old_table already done<br/>\n"; 
     continue; 
    } 
    $new_table = $table_prefix.$old_table; 
    echo "Renaming $old_table to $new_table<br/>\n"; 
    $query = "RENAME TABLE `$old_table` TO `$new_table`"; 
    mysql_query($query); 
    }