Magento change database table prefix

I accidentally installed a Magento installation without underscore for a table prefix. Is there any way to change this automatically? I do not like to change 337 tables manually :-)

I tried this solution, but it does not seem to work.

Michael

+4
source share
3 answers

You can create sql to rename all tables with this selection:

SELECT 'rename table '||table_name||' to '||'newprefix'||table_name||';' FROM information_schema.tables 
+1
source
 <?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);} ?> 

Steps:

  • take a backup of the database.
  • Create a file called "rename_table_prefix.php" and place it in the root directory.
  • Paste the above Script into it.
  • run the file http: www.domain.com/magento/rename_table_prefix.php
  • All tables will be renamed.
  • go to application /etc/local.xml
  • change the following line:
  • everything is ready.
0
source

I ran this php script to change the Magento DB table prefix

 // mege_rename_table_prefix.php //New Prefix Name $table_prefix = "test_"; //Magento Database Backup PHP  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); } 
0
source

All Articles