During the installation of Magento you have the option to use a database prefix for your Magento tables in the database. Using such a database prefix adds to the security of your site, because generic SQL Injection attacks will be more likely to fail. But if you installed Magento using the demo-data or if you forgot about this thing during installation, you are stuck with a database without prefix. Here is the procedure to update your MagentoTM instance with a different prefix.
Renaming all database tables
Renaming database tables could be done manually through a tool like phpMyAdmin, but because a default Magento install counts over 200 tables, this task is better performed by using a PHP-script. Open up a file and add the following PHP-code to it:
<?php $database_host = "localhost"; $database_user = "root"; $database_password = "root"; $magento_database = "magento2"; $table_prefix = "dwz_";
Make sure these settings match your own Magento installation. The $database_host is most likely "localhost", but it could be different. Consult your hosting provider for these details, or open up the Magento file app/etc/local.xml which already contains these details.
The settings contain the variable $table_prefix which is set here to "dwz_". The prefix could be changed into something else. We recommend you use only alphabetical characters and end the prefix with an underscore ("_"). These configuration settings are used in the rest of the PHP-script. Add the following PHP-code to the same file:
$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); }
Save the file to a name like "rename_table_prefix.php" (ending with a ".php" extension) and upload it to your Magento website.
Run the script
Before you run the script you should ofcourse prepare a database backup and a file backup. Also make sure you know how to restore these backups. If you are ready for it, just run the PHP-script by entering the right URL in your browser:
http://MAGENTO/rename_table_prefix.php
This should rename all the database tables to include the new table prefix. If this went ok, remember to delete the PHP-script afterwards.
Modifying the Magento configuration
Now that the database tables are modified, you will also need to modify the Magento configuration. Open up the file app/etc/local.xml and locate the following line:
<table_prefix><![CDATA[]]></table_prefix>
Change it to point to the new table prefix:
<table_prefix><![CDATA[dwz_]]></table_prefix>
That's it. It might be that you need to empty out the Magento cache directory (MAGENTO/var/cache) but normally everything should be working right away.
Tutorials on Magento administration
- Video: Speed Up Magento with mod_deflate
- Video: Magento extension install using SSH terminal
- Unable to login into the Magento backend
- Video: Create menu item in navigation bar Magento
- Magento backup through phpMyAdmin
- Compressing Magento output
- Magento categories and products are not showing
- Video: Magento setup of MultiSafepay
- Video: Magento Enterprise 1.6 to 1.7 upgrade
- Video: Delete Any Order in Magento by Yireo
- Video: Delete Orders in Magento by Boutique Circus
- Video: Remove Estimate Shipping and Tax block in Magento
- Changing the ordernumber in Magento
- Magento 1.4 cronjobs
- Fixing URL Rewrites with Magento
- Disabling Magento modules
- Analysing logfiles with Magento
Tutorials on MageBridgeTM administration
- Performance tuning with MageBridge
- MageBridge SEO Guide
- MageBridge scenarios
- Authentication guide for MageBridge
- Using MageBridge modules
- Step-by-step: Activating MageBridge plugins
- Upgrading Magento, Joomla! and MageBridge
- Configuring payment methods in MageBridge
- MageBridge Security Guide
- Step-by-step: Creating a MageBridge Menu-Item
- Step-by-step: Create a Magento API user
- API permissions with MageBridge
- How to use URL-suffices with MageBridge?
- Using MageBridge stores to load a different Magento theme
- Step-by-step: Adding a custom Magento block
- Managing MageBridge extensions
- Using the MageBridge Content Plugin
- Enabling SSL for MageBridge
- Prevent direct access to Magento
- Switching stores with MageBridge
- Migrating users between Joomla! and Magento
- Using MageBridge Product Connectors
- Best practices with MageBridge
- Using the MageBridgeLinks/JCE-plugin
- Moving a MageBridge site
- Importing and exporting users
- Two VirtualHosts but one domain
- Removing MageBridge
- Disabling user synchronization in MageBridge
- Questions to ask your hosting provider
- MageBridge caching
- Setting the MageBridge URLs in Magento


