How to Set Up MySQL in Django


In this article, we show how to set up MySQL in Django.

By default, SQLite3 is installed and set up in Django for you once you've installed Django.

This is fine for testing purposes such as when you're running your website on your computer's local server. However, when you are putting your site live on the internet, you want to switch from SQLite3 to another database server such as MySQL or PostgreSQL.

So how do you set up MySQL in Django?

And this is done in the file.

Specifically with the DATABASES dictionary

So in the DATABASES dictionary, you simply have to specify which engine you are using. We are setting up MySQL, so in this case, we are using the MySQL database engine.

Then in order to connect to the specific database, you have to specify the hostname for the database, the user of the database, and the password, just like you normally would have to do in order to connect to a MySQL database.

And this is all that is required to set up MySQL in Django.

As long as you're uploading this to a host that supports MySQL, then this will work.

If the host does not have support for MySQL, this will not work.

If you are going to run this on your computer's local server, then you have to have MySQL server installed on your computer.

MySQL can only work if there is a MySQL server in place that handle MySQL databases. Therefore, if you're running it either on the internet or on a local server, there must be a MySQL server that can serve up and handle MySQL databases.

And this is all that is needed to set up MySQL in Django.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...