Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:57:33+00:00 2026-06-18T07:57:33+00:00

Sample database configuration for MySQL : DATABASES = { ‘auth_db’: { ‘NAME’: ‘auth_db’, ‘ENGINE’:

  • 0

Sample database configuration for MySQL :

DATABASES = {
    'auth_db': {
        'NAME': 'auth_db',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'swordfish',
    },
    'master': {
        'NAME': 'master',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'spam',
    },
    'slave1': {
        'NAME': 'slave1',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'eggs',
    },
    'slave2': {
        'NAME': 'slave2',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'mysql_user',
        'PASSWORD': 'bacon',
    },
}

Does Django connect to all of them initially, even if some of the databases are not used at all ?
eg.

Using raw cursors with multiple databases

If you are using more than one database you can use
django.db.connections to obtain the connection (and cursor) for a
specific database. django.db.connections is a dictionary-like object
that allows you to retrieve a specific connection using its alias:

from django.db import connections

cursor = connections[‘my_db_alias’].cursor()

So here,
1. the connections object contains already made connections ? Or does it connect when a request for cursor is made ?
2. Is there a way to change this default behaviour and have the connections made on demand, ( All of the querying is as raw querying, and all databases are MySQL ) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:57:35+00:00Added an answer on June 18, 2026 at 7:57 am

    A persistent connection will be made to the requested database on the first access using django.db.connections. That is, connections are lazily evaluated and connected only on first use. The relevant code is in django/db/__init__.py in the ConnectionHandler class.

    Connections are not automatically removed after a query however, the connection will remain until disconnected. If there are entries in DATABASES which are never used, no connection will be made to these databases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sample page that uses 2 PHP files and a MySql database,
All, I have a WPF application built upon SQLite database and user/application Configuration settings.
I have installed a sample database, specifically Northwind from http://msdn.microsoft.com/en-us/library/8b6y4c7s.aspx . After installing the
I am looking for some adequately-complex sample database schemas that I could use for
I wrote a symfony task to fill a database of sample data. Here's a
I am looking for suggestions on database design for a sample jobs listing application.
i created the following sample method in business logic layer. my database doesn't allow
Say you have a string 3.4564. A sample set in the database has these
During our build process, we run sqlldr to populate our database with some sample
I have a table in a database which is used for storing application configuration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.