Cara menggunakan pythonanywhere mysql

Table of Contents

  • Can't connect to MySQL server
  • Can't connect to MySQL server on localhost in Django?
  • Can not connect to local MySQL server?
  • How do I access MySQL server on localhost?
  • How connect MySQL to Django?

Can't connect to MySQL server

Hi,

I can't run python manage.ph migrations from bach console. whatever I try it always raises this host issue:

File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 227, in get_new_connection return Database.connect(conn_params) File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/MySQLdb/init.py", line 85, in Connect return Connection(*args, kwargs) File "/home/XYZ/.virtualenvs/msgl/lib/python3.7/site-packages/MySQLdb/connections.py", line 204, in init super(Connection, self).init(args, *kwargs2) django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'XYZ.mysql.pythonanywhere-services.com' (110)")

Thanks for your support in advance. Sezen E.

deleted-user-4786229 | 4 posts | Nov. 9, 2018, 3:51 a.m. | permalink

Are you sure you're using the correct hostname and username from your Databases tab and are you sure you have the correct Django settings as described here: http://help.pythonanywhere.com/pages/UsingMySQL/?

Cara menggunakan pythonanywhere mysql

glenn | 8348 posts | PythonAnywhere staff | Nov. 9, 2018, 11:19 a.m. | permalink

hi , I think so, This is what I have in my databases tab (I just replaced my user name with XYZ):

MySQL settings Connecting:

Use these settings in your web applications. Database host address: XYZ.mysql.pythonanywhere-services.com

Should I use something else?

thanks Sezen

deleted-user-4786229 | 4 posts | Nov. 9, 2018, 11:33 a.m. | permalink

No, but make sure that the other parts of the DATABASES settings entry are also correct.

glenn | 8348 posts | PythonAnywhere staff | Nov. 9, 2018, 3:15 p.m. | permalink

thanks for the response Glenn.

Here is what I have in database settings, which looks good to me:

DATABASES = {

'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'xyz$abcdb',
    'USER':'xyz',
    'PASSWORD':'abcpassword',
    'HOST':'xyz.mysql.pythonanywhere-services.com',
    'PORT':'5432',
}

}

Why would it complain that it cannot connect to the database: 2003, "Can't connect to MySQL server on 'XYZ.mysql.pythonanywhere-services.com' (110)")

Is it physical access issue, I mean in networking layer or is it credentials issue preventing django to login to the database?

I can login to the database through the console successfully:

mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | xyz$default | | xyz$abcdb | +--------------------+ 3 rows in set (1.97 sec) mysql>

Thanks again in advance for your support.

deleted-user-4786229 | 4 posts | Nov. 9, 2018, 3:26 p.m. | permalink

Your port is wrong. Either use the correct default of 3306, or just leave it out entirely.

glenn | 8348 posts | PythonAnywhere staff | Nov. 9, 2018, 3:45 p.m. | permalink

thanks glenn good catch, I had overlooked the port when I changed it from postgreSQL to mySQL. It works well after updating the port.

Thanks

deleted-user-4786229 | 4 posts | Nov. 11, 2018, 3:11 a.m. | permalink

import os

import sys

path='/home/sivaprasad/myproject'

if path not in sys path:

os.environ['DJANGO_SETTINGS_MODULE']= 'myproject.settings'

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

what is the error in this i can't understand here this code is used in wsgi.py fileand the error is syntax error in if class

deleted-user-6302842 | 1 post | Oct. 12, 2019, 6:32 a.m. | permalink

This line is not correct:

it should read:

glenn | 8348 posts | PythonAnywhere staff | Oct. 12, 2019, 11:03 a.m. | permalink

Find your mysqld.sock file location then add it to HOST using xampp on Linux mysqld.sock file is in another location, therefore, it is not working for /var/run/mysqld/mysqld.sock

DATABASES = {

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db_name',
        'USER' : 'root',
        'PASSWORD' : '',
        'HOST' : '/opt/lampp/var/mysql/mysql.sock',
        'PORT' : ''
    }
}

Or Run MySQL server first then execute MySQL.

$ mysql.server start

$ mysql -h localhost -u root -p

Can't connect to MySQL server on localhost in Django?

This is my settings.py file config for my django app. Same for you please take host "127.0. 0.1" and port "3306". This might solve your problem..

Actually the problem in my case was that I was using "localhost" instead of "127.0. ... .

In my case, I accidently supplied the username as the password..

Can not connect to local MySQL server?

Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.

How do I access MySQL server on localhost?

Enter 127.0. 0.1 for the host. The default username for a new MySQL installation is root, with a blank password. You can leave the port field blank unless your server uses a different port than 3306.

How connect MySQL to Django?

We use the following steps to establish the connection between Django and MySQL..

Step - 1: Create a virtual environment and setting up the Django project..

Step - 2 Create new Database..

Step - 3: Update the settings.py..

Step - 4 Install mysqlclient package..

Step - 5 Run the migrate command..