Ghost博客数据库迁移至MySQL

为什么要迁移数据库?

刚刚开始,这个博客是由Ghost + CentOS7 + sqlite3 搭建的。然而自己对于sqlite3不是特别的熟悉,所以决定,将其迁移至MySQL来。但是在迁移的过程中,还不是那么的顺利,就用笔记记录下来吧。

升级阿里云的配置

之前购买的虚拟云主机是最低配置的,1核 + 512M内存。这个配置基本也就能刚好跑跑一个Ghost。因为当时的内存使用率基本就到了90%左右,所以在安装mysql的时候,直接就报错,内存不够,所以,就把当前的云主机升级为了1核 + 1GB内存。费用由原来的每个月30RMB多到了50RMB多,其他厂家的云主机的价格都感觉差不多,阿里的技术我比较信赖,毕竟在11.11这么大并发的情况下,可能抗住。是一个伟大的公司,值得所有人的敬佩。

升级完后,需要在控制台重启机器,配置才会得到更新,其他的方式,介绍说不可以。

安装mysql

按照以前的方式安装mysql竟然不行了,原因是因为系统是CentOS7的。

如何查看系统的相关信息呢?

[cyblogs@iZ94tq694y3Z ~]$ cat /etc/redhat-release 
CentOS Linux release 7.0.1406 (Core) 

系统原来是当时买云主机的时候选择的。

回顾一下原来是如何安装mysql on CentOS的

yum install mysql mysql-server mysql-devel

但是运行下来,发现报错,说mysql-server没有找到,所以这里就安装失败了。通过查阅资料,找到了正确的安装操作说明。

1、- We use Yum to Remove MySQL, like so: yum remove mysql mysql-server

2、- With MySQL removed, we can safely backup the configuration: mv /var/lib/mysql /var/lib/mysql_old_backup If you'd rather remove it, issue: rm -vR /var/lib/mysql

3、- Now we can safely reinstall MySQL, using the default configuration that is included in the package from the Official MySQL repository (we need wget to fetch the rpm that will update your repos):

4、- yum install wget

5、- Verify the repositories are installed: ls -1 /etc/yum.repos.d/mysql-community*

  • Issue the actual install command (This will replace the mysql-server in the CentOS repository with the official package from upstream MySQL):
  • yum install mysql-server

6、- Use the script provided to set the root password, now that we have a fresh install again: mysql_secure_installation

7、- If you ever need to set the password after using the script, use: mysql -u root

8、- Now you can use the standard commands from systemctl, part of systemd to Start and Stop the daemon like so:

  • systemctl start mysqld

按照上面的步骤一步步的操作,应该没有什么太大的问题。因为,我已经安装成功了。

给用户设置密码以及赋予权限

mysqladmin -u root password root (自己的密码)

grant replication slave on *.* to 'root'@'%' identified by 'root';

此时,基本在mysql这一步就OK了。自己可以尝试着登录,操作sql语句查看一些一些表的信息。

备份之前sqlite3的数据,方便后面的重新导入。

输入 http://hostname/ghost/settings/labs/ 可以看到这个页面。 image 点击Export就可以导出数据了,文件名字是这样子的mr-chen.ghost.2015-11-21.json数据JSON格式的数据。

修改Ghost的配置文件

之前用sqlite3的配置 config.js 中的production模块

	database: {
   	client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },
        

修改成mysql的配置

database: {
            client: 'mysql',
            connection: {
                host: 'localhost',
                user: 'root',
                password: 'root',
                database: 'cyblogs',
                charset: 'utf8'
            },
            debug: false
        },

然后将文件替换掉,重启服务。

如果重启服务后,不能访问,有可能你的iptatles没有开放80端口,需要设置一些防火墙。

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT

然后访问自己的网站,就可以正常的工作了。最后再将输入导入进去,但是发现背景图片与用户自己的头像都丢失了,需要用户自己重新上传。

但是在上传用户头像的时候,ghost报错了。错误提示:

ERROR: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2015-03-18T02:14:41.000Z' for column 'created_at' at row 1

之后在,gitbub上找到了答案,需要在mysql的配置文件中,重新设置一下。

Hi @keesun, sorry to hear you're having trouble.

Although I've seen this problem before with other software, I've never seen it reported with Ghost before, and I can't find anyone reporting it to >bookshelf or knex either.

Not sure specifically why this is happening to you, but it may be to do with your specific version of MySQL.

The fix is to first locate your my.cnf file (often somewhere like /usr/local/my.cnf /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf).

Then, inside of that file remove STRICT_TRANS_TABLES from the sql-mode line, and restart MySQL. All should then be fine.

I don't think there's an issue here for us to fix. Perhaps we ought to be using timestamp rather than datetime fields, however as it should be easily >fixable with a config change, unless we get lots of people running into this I don't think it needs looking into at this stage. Therefore, I'm going to >close this for now - and if we get more reports we can reopen.

删除掉 STRICT_TRANS_TABLES,然后再重新启动mysql服务就好了。

转载于:https://my.oschina.net/vernon/blog/551700

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值