背景:

Wordpress安装时数据库指定不正确,导致网站上的数据都放到了mysql这个系统库中。


mysql> show tables from mysql;

+---------------------------+

| Tables_in_mysql           |

+---------------------------+

| columns_priv              |

| db                        |

| event                     |

| func                      |

| general_log               |

| help_category             |

| help_keyword              |

| help_relation             |

| help_topic                |

| host                      |

| ndb_binlog_index          |

| plugin                    |

| proc                      |

| procs_priv                |

| servers                   |

| slow_log                  |

| tables_priv               |

| time_zone                 |

| time_zone_leap_second     |

| time_zone_name            |

| time_zone_transition      |

| time_zone_transition_type |

| user                      |

| wp_commentmeta            |

| wp_comments               |

| wp_links                  |

| wp_options                |

| wp_postmeta               |

| wp_posts                  |

| wp_term_relationships     |

| wp_term_taxonomy          |

| wp_termmeta               |

| wp_terms                  |

| wp_usermeta               |

| wp_users                  |

+---------------------------+

 

mysql库中放的mysql数据库自身的数据,所以我们希望把网站的数据重新放到wordpress库。 


思路:

首先将mysql库中属于wordpress的数据备份到/back/mysql下,再把备份的数据恢复到wordpress库中。 


操作:

第一步:写一个备份脚本

[root@localhost mysql]# cat wp_backup.sh

for tname in ` mysql -uroot -p'dong' -e "use mysql;show tables like 'wp_%'"|grep -iv tables`

do

tname_all="$tname_all $tname"

done

#echo $tname_all

mysqldump -uroot -p'dong' mysql $tname_all >/backup/mysql/wp_all_back.sql

第二步:验证脚本的正确性后,执行脚本

第三步:将备份的数据恢复到wordpress库中

第五步:验证结果

mysql> show tables from wordpress ;

+-----------------------+

| Tables_in_wordpress   |

+-----------------------+

| wp_commentmeta        |

| wp_comments           |

| wp_links              |

| wp_options            |

| wp_postmeta           |

| wp_posts              |

| wp_term_relationships |

| wp_term_taxonomy      |

| wp_termmeta           |

| wp_terms              |

| wp_usermeta           |

| wp_users              |

+-----------------------+

12 rows in set (0.00 sec)

第六步:修改wordpress连接的库

最后网站也运行正常,结束。


更多博客请访问:www.ayard.com.cn