答案 0 :(得分:1)
您可以使用以下选项创建sql以重命名所有表:
SELECT 'rename table '||table_name||' to '||'newprefix'||table_name||';'
FROM information_schema.tables
答案 1 :(得分:0)
<?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);}
?>
步骤:
答案 2 :(得分:0)
我运行这个PHP脚本来更改Magento DB表前缀
// 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);
}
答案 3 :(得分:0)
您可以简单地在PHPMyAdmin中进行更改。
Click/open the database.
Click Structure at the top bar.
This will display all your tables. Note the existing prefix.
Scroll to the bottom, to the last table.
Click "Check all".
This will check all tables.
Click the drop down menu just next to it - the one with the default value "with selected".
Select "Replace table prefix:"
This will bring you to a new page with two text inputs.
Fill in your existing prefix, e.g. "oldPrefi_". Don't forget the underscore.
Fill in your new prefix, e.g. "newPrefi_". Don't forget the underscore.
Finally, click submit.
您将使用新的前缀重定向到表列表。
答案 4 :(得分:0)
第1步-更改env.php文件中的table_prefix,如下面的屏幕截图所示
步骤2-运行以下查询以获取ALTER语句以将前缀添加到现有表中-:
SELECT Concat('ALTER TABLE ', TABLE_NAME, ' RENAME TO qa_',
TABLE_NAME, ';') FROM information_schema.tables WHERE table_schema =
'DB_NAME'
第3步-通过在您的Magento根文件夹上运行以下命令来升级Magento 2数据库
php bin/magento setup:upgrade
万一出了问题,您可以从 env.php 中删除 table_prefix ,然后在数据库实例上运行以下查询,以将表重命名为原始表。
SELECT Concat('ALTER TABLE ', TABLE_NAME , ' RENAME TO ',
replace(TABLE_NAME,'qa_',''), ';') FROM information_schema.tables
WHERE table_schema = 'magento_2'
希望它对某人有帮助!
答案 5 :(得分:0)
解决该问题的步骤(100% 有效,我遇到了同样的问题,我已解决)
以上解决方案大多不起作用,因为您可以更新表名,但是 FORIEGN 键映射会导致问题。因此,以下是解决此问题的最佳方法。