Typecho博客网站迁移:MySQL ➡️ MarialDB

发布时间 2023-10-09 18:57:56作者: realXuan

1. 引言

由于服务、价格等因素更换云服务器是很常见的情况,本文记录了Typecho博客网站从原服务器迁移至新服务器的操作过程,其中涉及了Mysql数据库到MarialDB数据库的迁移。新服务器为腾讯云轻量服务器,镜像采用typecho,初始服务器状态如图所示。将网站从迁移主要有如下几个步骤:Typecho自定义配置迁移➡️数据库迁移➡️Nginx配置➡️自定义主题配置。
image

2. Typecho的自定义配置迁移

网站迁移的第一步是将原服务器的“./typecho/usr”目录下的代码复制到新服务器的相同目录内,如此可以完成自定义主题和插件的大部分内容的迁移。

3. 数据库迁移:MySQL- > MarialDB

接着,网站文件之外的数据要通过数据库来迁移内容。新服务器所使用的数据库是MarialDB。MarialDB是一个开源的关系数据库管理系统,是在MySQL数据库的分支基础上进一步开发的,其对MySQL数据库有很好的兼容,所以,将原服务器的MySQL数据库迁移至新服务器的MarialDB数据库还是挺容易的。

3.1 在原服务器中备份并导出数据库文件

mysqldump 是 mysql 用于转存储数据库的命令,用于导出所有数据库的内容,包括表结构和数据。用于导出所有数据库的内容,包括表结构和数据。--all-databases参数表示导出所有数据库的内容,mysqldump 在导出操作中会包括所有可用的数据库。

mysqldump --all-databases --user=typecho --password > backupdb.sql
Enter password: (在此输入密码后按回车)

3.2 将“backupdb.sql”文件拷贝至新服务器并导入数据

使用MySQL命令行工具将backupdb.sql数据库备份文件导入至新数据库中,实现数据库的迁移。

mysql -u root -p < backupdb.sql
Enter password: (在此输入密码后按回车)

4. Nginx配置

完成数据库迁移后,还需要对Nginx进行配置。

user                 nobody;
worker_processes     auto;
worker_rlimit_nofile 65535;

error_log  logs/error.log  notice;

events {
    accept_mutex off;
    use epoll;
    worker_connections  8192;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format       combinedio  '$remote_addr - $remote_user [$time_local] '
                                 '"$request" $status $body_bytes_sent '
                                 '"$http_referer" "$http_user_agent" $request_length $request_time $upstream_response_time';
    access_log logs/access.log combinedio;

    sendfile                     on;
    gzip                         on;
    tcp_nopush                   on;
    tcp_nodelay		         on;

    keepalive_timeout            0;
    client_body_timeout          10;
    client_header_timeout        10;

    client_header_buffer_size    1k;
    large_client_header_buffers  4  4k;
    output_buffers               2  32k;
    client_max_body_size	 64m;
    client_body_buffer_size      256k;

    server_tokens off;

    include http.d/*.conf;

    server{
        location /server-status {
#           stub_status  on;
            allow        127.0.0.1;
            deny         all;
        }


        location /status {
            include      fastcgi.conf;
            fastcgi_pass 127.0.0.1:9000;
            allow        127.0.0.1;
            deny         all;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    include include/*.conf;
}
server {
    listen 80 default_server;
    listen       443 ssl;
    server_name  /* 这里写域名 */;
    ssl_certificate /* 这里写证书文件的相对路径或绝对路径 */;
    ssl_certificate_key /* 这里写私钥文件的相对路径或绝对路径 */;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    server_tokens off;

    keepalive_timeout 5;

    root /usr/local/lighthouse/softwares/typecho;
    index index.php index.html;

    access_log logs/typecho.log combinediox;
    error_log logs/typecho.error.log;

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }

    location ~ .*\.php(\/.*)*$ {
        include fastcgi.conf;
        fastcgi_pass   127.0.0.1:9000;
    }
}

5. Handsome主题操作

如果使用Handsom主题,还需要在迁移前备份主题数据以及在迁移后恢复主题备份数据。