Change table prefix drupal hosting
I have a drupal 7 site running on a webserver, it is currently using a database that was created with out a prefix.
I am attempting to restore that database to a new drupal instance from a shared hosting provider. I am using the Backup and Restore Module to move the database. One thing I have no apparent control of is that their "quick install script" creates a new drupal database with a "drupal_" prefix.
Do I need to convert my existing database to have that prefix, because as it seems now my migrated changes are not even being read since it probably has both sites data sitting side by side, and the database information I want to be reading entries from don't have the prefix? Is that reasoning correct? If so how do I convert my Drupal database to the same one but now with the necessary prefix applied throughout?
asked Mar 20 '13 at 15:07
If you have phpMyAdmin the simplest way is to:
- go to the "Structure" tab (where there is the list of tables).
- select all the tables (with the "Check All" checkbox at the end of the list)
- in the dropdown list close to the "Check All" select the action "Add table prefix" (or "Replace table prefix" if that is the case)
- insert the prefix, press the button and let it do all the work.
After that remember to specify the prefix in the site\default\settings.php
answered Jul 29 '14 at 20:48
Mind that not all tables are selected when you "Check All", only the ones that are visible on the page. Drupal has many tables and there are other tables in page 2 that are not selected. Just do the same thing on page 2. - wranvaud Oct 20 '16 at 12:15
If it is just the database with the 'drupal_' prefix, you do not need to create a table prefix.
The database dump created by the Backup and Restore module does not include any database definition.
If you need it, you can extract the mysqldump file and add the following to the top of the file:
Otherwise, just change your database credentials in settings.php, and use the Backup and Restore module to reload your database.
This PHP script automates the renaming of multiple tables in a MySQL database. It lists all tables in a MySQL database, which contain a defined string pattern. The script creates and executes a series of SQL statements, which rename the table by replacing the search pattern in the original table name with another pattern in the new table name.
This script can easily be modified to rename multiple databases, or when stripping the original pattern (f.e. a prefix) and adding a new pattern (f.e. a suffix) is needed.
After running the script, you'll have to edit your settings.php to rename the db_prefix setting. After the script is run, you may get a pdo error: "PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table '[database].semaphore' doesn't exist. in lock_may_be_available()". If this happens: 1) rename your settings.php to something like settings-old.php; 2) copy the default.settings.php to the sites/default folder and rename it to settings.php. This will cause the install script to run. When prompted for your database settings, enter the name of your existing database. The install script will inform you that the database already exists and offer to take you to your site.
answered Dec 15 '13 at 5:25
2017 Stack Exchange, Inc