简体   繁体   中英

Django MySQL Database location and setup

So I have a MySQL database for my Django project which I think is located in the default directly (wherever that should be). When I want to move my Django project to digital ocean, how do I move that database? The my.cnf file is located inside the same directory as the settings.py file for the Django project. I am using macOS.

In short: How do I copy my database file to my Django project directory and reconfigure its path to that?

Compare the MySQL versions of both servers. Ensure the new version isn't less than the current version. Also check its not two major versions ahead of the current one.

Ensure MySQL is stopped.

Copy/move the entire datadir to the new location. There should be no files in this new location that weren't in the original.

In the my.cnf file set datadir to the new location.

Copy the my.cnf file to the location where mysql is expecting to read this on the new server. Look at top of mysqld --help --verbose if you have doubts where this is.

There are many things to consider here,

  • In Digital Ocean you would have MySQL server running on same machine as the Django server ie just like your local machine?
  • If yes then you might not have to change anything on django settings (if you keep user and password same as local).
  • If No, you might need to change host in django to IP of that server(there are many things involved here...)
  • Regarding the data transfer, it is always the best practice to dump MySQL and Import it in new DB. There are many guides available on web. Here is one from Digital ocean .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM