上下文:我正在开发 Spring MVC 项目并使用 Hibernate 使用注释从我的类生成数据库模式。它使用在我的本地机器上运行的 MySQL 服务器。我的目标是获得托管并使我的网站上线。
- 在这种情况下,我是否使用托管服务提供商的 mySQL 服务器来运行我的数据库?
- 优缺点都有什么?他们通常会做数据库备份还是值得自己做这件事并将其存储在我的机器上?
- 如果服务器重新启动,我会丢失数据吗?
提前致谢。我对此很陌生,因此如果听起来不合理,请随意调整问题。
上下文:我正在开发 Spring MVC 项目并使用 Hibernate 使用注释从我的类生成数据库模式。它使用在我的本地机器上运行的 MySQL 服务器。我的目标是获得托管并使我的网站上线。
提前致谢。我对此很陌生,因此如果听起来不合理,请随意调整问题。
这在很大程度上取决于您托管网站的方式。我建议研究 CloudFoundry,它是 VMWare 人员提供的免费平台即服务 (PAAS)。如果您使用 Spring 设置休眠,Cloudfoundry 可以自动将您的应用程序挂钩到它提供的 MySql 服务。
无论如何,您的数据库很可能驻留在主机服务器上,除非您为您的机器建立一个静态 IP 并公开数据库服务。那时,您不妨托管自己的网站。
数据的存储位置取决于主机的类型。例如,如果您使用 PAAS,他们将选择将您的数据库存储在服务器上的位置。这对你来说是透明的。如果您使用专用服务器,您很可能必须安装数据库软件。
大多数支持网站的数据库应该提供持久存储或配置为这样做。我不确定为什么您的 MySql 数据库在您重新启动后会丢失数据,但开箱即用它不应该这样做。如果您使用 hibernate 自动生成 DDL,我可以看到每次重新启动时数据都会被吹走。您可能希望摆脱这种配置。
1 Do I use mySQL server of a hosting provider in that case to run my database?
Yes. In your application you only change the JDBC connection URL and credentials.
There are other details about the level of service that you want for the database: security, backup, up time. But that depends on your hosting provider and your application needs.
2 Is it stored somewhere on the server?
Depends on how your hosting provider hosts the database. The usual approach is to have the web server in one machine and the database in another machine inside the VPN.
From the Hibernate configuration perspective, is just changing the JDBC url. But there are other quality attributes that will be affected by your provider infrastructure, and that depends on the level of service that you contract.
3 Should I declare somehow that data must be stored f.e. in a separate file on server?
Probably not. If your provider gives you a database service, what you choose is the level of service: storage, up-time... they take care of providing the infrastructure. And yes usually they do that using a separate machine for the database.
4 Am I going to loose data in case of server reboot? (As f.e. I do when I restart server on my local machine)
Depends on the kind of hosting that you are using. BTW Why you loose the data on reboot in your local machine? Probably you are re-creating the database each time (check your Hibernate usage). Because the main feature of any database is well... persistent storage :)
If you host your application in a virtual machine and you install MySQL in that VM... yes you are going to loose data on reboot. Because in this kind of hosting (like Amazon EC2) you host a VM for CPU execution, and all the disk data is transient. If you want persistent data you have to use a database located in another machine (this is done in this way for architectural reasons, and cloud providers like Amazon gives you also different storage services).
But if the database is provided, no.. a persistent database is the usual level of service that you should expect from a provider.