英文:
Automatically create database in python application
问题
我相对于应用开发还比较新,但我正在开发一个个人项目,希望能够在首次安装或通过应用程序中的选项自动部署一个mariadb/mysql数据库。我理解在设置好mariadb服务器后如何创建数据库,并且已经实现并运行了这一部分。但我希望不必安装mariadb、配置服务器等,而是让应用程序自动处理这些事情。我觉得这应该是可能的,但我还没有找到如何实现的答案。
英文:
I am relatively new to application development, but I'm working on a personal project and I would like it to automatically deploy a mariadb/mysql db on first install/through an option in the application. Now, I understand how to create a db, after the mariadb server has been set up, and I've got that part implemented and working. But what I would like to do is not have to install mariadb, configure the server, etc, and have the application handle that automatically. I feel like it must be possible, but I haven't been able to find an answer on how to implement it.
答案1
得分: 1
抱歉,我只能回答你的翻译请求,不能提供任何额外的信息。以下是翻译结果:
你不能让你的应用程序自动安装MariaDB并在你运行它的机器上进行配置。即使可以,你也不会想这样做。
如果你想自动安装和配置数据库,那么在新机器上首次运行程序时可能会花费很长时间来安装数据库。如果你确实想要自动安装和配置,那么最好编写(或在网上找到)一个bash脚本来执行。然后,你可以单独运行该脚本,不必担心任何意外的副作用。
此外,在生产环境中,你的数据库通常甚至不会在与Web应用程序相同的机器上,特别是如果你在Docker或其他形式的容器化上运行它。这样做的目的是减轻Web应用程序的压力,让另一台隔离的机器处理所有数据库事务。你也可以使用一个服务来为你处理数据库,这样你就不需要安装或配置任何东西,只需提供你的Web应用程序数据库的URL、用户名和密码即可。如果你不想进行任何数据库配置,这可能是你最好的选择。我在这里不会花时间列举可以为你做这些事情的服务,但你可以通过谷歌搜索“MariaDB托管”来找到成百上千个选项。
英文:
You can't have your application automatically install MariaDB & configure it on the machine you're running it on. And even if it could, then you wouldn't want to do that.
If you were to automatically install and configure the DB, then whenever you run your program for the first time on a new machine, it could take a really long time to install the DB. If you do want to automatically install & configure, then you're better off writing (or finding online) a bash script to do it. Then, you can just run the script separately and don't have to worry about any unexpected side effects.
Also, most of the time in production your DB isn't even on the same machine as your web app, especially if you're running it on Docker or some other form of containerization. The point of this is to take the strain off of the web app and let another isolated machine handle all the DB stuff. You could also use a service to handle your DB for you, so you don't have to install or configure anything, just provide your web app the URL, username, and password of your DB. This is likely your best bet if you don't want to do any DB configuration. I won't spend any time here listing services that can do it for you, but you can find hundred by just doing a Google search for "MariaDB hosting".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论