On the knowledge of database table prefixes

Source: Internet
Author: User
Tags php script preg

zblogphp default installation, the use of MySQL database, the load capacity is stronger!

So

1, configure the time, how to set the database table prefix it?

2, two, multiple zblogphp how to install to the same database?

Below to answer this question:

The configuration page is displayed when MySQL is installed, such as:

The four cutting heads are: Database user name, database password, database name, database table prefix !

The last red Arrow is the installation zblogphp default prefix, the default is: Zbp_

In general, if a MySQL database has only one zblogphp installed, the database table prefix is used by default, but if the database as shown in Zblog has multiple zblogphp installed at the same time, these table prefixes cannot be the same. Otherwise it will overwrite the other table prefix zblogphp data, so multiple zblogphp installed in the same database must be installed in the time to differentiate table prefixes, such as the use of domain name shorthand, if your domain name is baidu.com, you can consider using baidu_ as a table prefix!

Let's see one of my theme. More than 10 zblogphp are installed in the database, and the table prefixes are different!

Shown, is old white all the template demo stations are independent, but the data are placed in the same MySQL, just differentiate the table prefix!

I installed more than 10 zblogphp in the same MySQL, only need to change the table prefix of MySQL database when installing.

Table Prefixesand how to bulk modify table prefix names:

MySQL database table prefix, this is the way we differentiate other tables, when we have multiple systems in the same database, the table prefix is a unique identifier. When we use the PHP Open source program to install the site, the General database table prefix is set by default, such as: WordPress default database table prefix is wp_,echosp default database table prefix is ecs_,discuz default database table prefix is pre_, The default database table prefix for the Dream Content Management System (Dede) is dede_. In its official installation tutorials or in the open source system security installation method, it is recommended to modify the default table prefixes known to the world as they are installed. If you're not careful, what if you've already used the default table prefix? Is there a way to change it? Worry-free host (www.51php.com) small, today with Ecshop online open source system demo, how to modify the ecshop MySQL database table prefix name.

Changes involving the database are very dangerous, so backups are not minimal. It is recommended that you back up your site database in a PHP virtual host using two or more methods. Worry-free host space Control Panel also provides backup functions, you can refer to the "site full station one-click Backup and Recovery." There are two methods to modify in the tutorial, one for batch modification (using PHP footstep) and one for exact modifications (using SQL query statements).

Method One: Use SQL statements to modify MySQL database table prefix names

First of all we think of is to use SQL query statement to modify, this method is also very convenient, just enter the worry-free host Control Panel--phpmyadmin login, in the Run SQL query box, enter the following name.

ALTER table name RENAME to new table name;

Such as:

ALTER TABLE old_post RENAME to New_post;

SQL query statement has a disadvantage, that is, a SQL statement can only modify the table name of a database, if you want to accurately modify a table, it is very useful. If there are many database tables, it is not recommended. Is there a method class for batch modification of multiple database table prefix names? Yes, please see the introduction below

Method Two: Php script bulk modify MySQL database table prefix

A quick batch method for modifying a data table prefix:

1, copy the following code to Notepad, according to their own situation to modify the database information, and saved the 51php.php. Upload your site's root directory again. You can download the MySQL database prefix name bulk Modify script: Modify the MySQL database table prefix name.

?
View Code
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 6667686970717273747576777879 <?php//设置好相关信息$dbserver=‘localhost‘;//连接的服务器一般为localhost$dbname=‘y8n9nghmze_shop‘;//数据库名$dbuser=‘y8n9nghmze_user‘;//数据库用户名$dbpassword=‘admin‘;//数据库密码$old_prefix=‘ecs_‘;//数据库的前缀$new_prefix=‘51php_‘;//数据库的前缀修改为if ( !is_string($dbname) || !is_string($old_prefix)|| !is_string($new_prefix) ){return false;}if (!mysql_connect($dbserver, $dbuser, $dbpassword)) {print ‘Could not connect to mysql‘;exit;}//取得数据库内所有的表名$result = mysql_list_tables($dbname);if (!$result) {print "DB Error, could not list tables\n";print ‘MySQL Error: ‘ . mysql_error();exit;}//把表名存进$datawhile ($row = mysql_fetch_row($result)) {$data[] = $row[0];}//过滤要修改前缀的表名foreach($data as $k => $v){$preg = preg_match("/^($old_prefix{1})([a-zA-Z0-9_-]+)/i", $v, $v1);if($preg){$tab_name[$k] = $v1[2];//$tab_name[$k] = str_replace($old_prefix, ‘‘, $v);}}if($preg){//        echo ‘<pre>‘;//        print_r($tab_name);//        exit();//批量重命名foreach($tab_name as $k => $v){$sql = ‘RENAME TABLE `‘.$old_prefix.$v.‘` TO `‘.$new_prefix.$v.‘`‘;mysql_query($sql);}print数据表前缀:.$old_prefix."<br>".已经修改为:.$new_prefix."<br>";}else{ print 您的数据库表的前缀.$old_prefix.输入错误。请检查相关的数据库表的前缀;if ( mysql_free_result($result) ) {return true;}}?>

2. Enter your URL in the browser/51php.php. The prefix of the database table can be modified successfully.

May 28, 2013 update:

Worry-free host gadget (www.51php.com) Another way to update a MySQL database table prefix today is to use a third-party tool, the imperial backup king, to modify it. Here's how it works:

1, log in to the Empire backup background, select "Backup Data"-"Batch Replace table name", and then perform the operation can complete the batch replacement, is also very simple. Such as:

The above methods can modify the site prefix, but most of the open-source programs to modify the table suffix, you need to modify the Web site program database configuration file, will let the site run. How to modify the database of the site can refer to the various open source program Help documentation.

This address: http://www.51php.com/mysql/7967.html

On the knowledge of database table prefixes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.