how can I do it?
I thought, I can read something from database, but it looks too much, is there something like?:
settings.DATABASES['default'].check_connection()
To test the connection to your database, run the telnet hostname port on your Looker server. For example, if you are running MySQL on the default port and your database name is mydb, the command would be telnet mydb 3306 . If the connection is working, you will see something similar to this: Trying 10.10.
To use MySql as the backend engine for a Django project, we need to follow a simple setup: Install the MySql Server (we can also use a remote one) Install the Mysql Python driver - used by Django to connect and communicate. Create the Mysql database and the user.
All you need to do is start a application and if its not connected it will fail. Other way you can try is on shell try following -
from django.db import connections from django.db.utils import OperationalError db_conn = connections['default'] try: c = db_conn.cursor() except OperationalError: connected = False else: connected = True
Run the shell
python manage.py shell
Execute this script
import django print(django.db.connection.ensure_connection())
If it print None
means everything is okay, otherwise it will throw an error if something wrong happens on your db connection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With