I'm using Django + mysql for days. And this morning I suddenly found that I cannot get connect with the remote mysql.
% python manage.py makemigrations
it raise
django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
also when
python manage.py runserver
Here's my environment:
macOS 10.15 + Django 2.2.6 + MySQL 5.7 (on a remote server, ubuntu 18.04) + python 3.6.8 (use conda env)
I've looked for some solutions like:
downgrade openssl
Package openssl conflicts for:
openssl=1.0.2r
python=3.6.8 -> openssl[version='>=1.1.1a,<1.1.2a']
add use_pure=True in my .conf file
nothing changed
add skip_ssl in my .conf file
nothing changed
note
On the server (which I deploy my site, ubuntu 18.04) my site run well using gunicorn + Nginx
All the things worked well until today.
The site broke when I found this issue but work well when I restart it.
I guess maybe some update on the server (automatically upgrade) to cause the problem, but haven't find it yet.
some of my code
# setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': mysqlPath,
'init_command': 'SET default_storage_engine=INNODB',
},
}
}
# my_remote.cnf (which define the 'mysqlPath' in setting.py)
[client]
database = mydatabase
user = myusername
password = mypassword
default-character-set = utf8
host = myremotehost
port = 3306
use_pure = True
skip-ssl
skip_ssl
skip-ssl = True
skip_ssl = True
It is because your server isn't set up for SSL (yet). Thus, the error is caused on the server-side.
As already mentioned and tried successfully, a solution is to either make the server SSL-ready or set skip_ssl to true while in development.
https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html
Related
I am trying to run a Django application on AWS Ec2 instance. I've chosen Ubuntu as my platform. After cloning the git repository, and creating a virtual environment, I have installed all apps in my requirements.txt. When I try to the following lines of code python3 manage.py migrate ; python3 manage.py check ; python3 manage.py runserver the following error is coming up.
django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db" connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db"
My settings.py file looks like this
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Database Engine of PostgreSQL Database
'NAME': 'columbus_db', # Database Name
'USER': 'columbus_db', # Database has a Root User
'PASSWORD': 'columbus', # Database Connection Password
'HOST': "localhost", # IP Address for Localhost
}
What can I change in settings.py or Ec2 Instance settings to start the application and see it at Ec2 IP address?
You are missing a running database, the app code except it to be PostgreSQL, you have multiple choices:
Install and run a local PostgreSQL instance directly in your EC2
Use Amazon's managed database RDS
Use Sqlite which is simple to setup and doesn't require more configuration, but your app might required specific PostgreSQL features
I have a Django app (Python 3.4, Django 1.7) on PythonAnywhere, along with a MySQL database.
The database is working fine on the deployed app.
However, I cannot get to connect it to the app on my local machine.
The following error is thrown when I run python manage.py runserver:
django.db.utils.InterfaceError: (2003, "2003: Can't connect to MySQL server on 'mysql.server:3306' (8 nodename nor servname provided, or not known)", None)
These are the attributes I use:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '<username>$<database_name>',
'USER': '<username>',
'PASSWORD': '<databse_password>',
'HOST': 'pythonanywhere.com'
}
}
I have also tried mysql.server and mysql.server.pythonanywhere.com as HOST without any more luck.
I think It's not possible to connect directly to your mysqlserver instance from remote, for security reason, the port 3306 is blocked.
They suggest to connect through SSH Tunnel, follow this link.I don't know If you can do an ssh tunnelling within Django, You should probably write a custom configuration. It's simpler to install an SSH Tunnel software on your PC and then connect your Django App to localhost on a port You have to choose.
Bye
As per PythonAnyWhere documentation :
Open a terminal and run below command.
ssh -L 3333:username.mysql.pythonanywhere-services.com:3306 username#ssh.pythonanywhere.com
provide your PAW account login password
replace username with your username.
Open another terminal and run below command.
mysql -h 127.0.0.1 --port 3333 -u username -p
provide your mysql password. Available in settings file.
keep terminal 1 open as long as you are working on terminal 2.
Accessing PythonAnyWhere MySQL from outside
Only Paid account have permission to access remoteserver for mysql database
After installing Tryton 3.0 from the ppa:rayanayar/tryton-3.0, as in the gist script on https://gist.github.com/sharoonthomas/5857450, I always get "wrong server password" when trying to create a new database via the Tryton Client.
Why is that? I've entered the global database admin password in /etc/trytond.conf as prescribed:
# Configure the Tryton server password
admin_passwd = my_admin_password
I've checked that
the tryton user exists in postgreSQL and as Linux user and has his name and password in trytond.conf
the PostgreSQL server ist restartet
root#Tryton:~# service postgresql restart
* Restarting PostgreSQL 9.1 database server [ OK ]
the Tryton server is restarted and running
root#Tryton:~# sudo /etc/init.d/tryton-server restart
* Restarting Tryton Application Platform trytond
start-stop-daemon: warning: failed to kill 50063: No such process
[ OK ]
root#Tryton:~# ps aux | grep trytond
tryton 37312 0.2 1.0 292796 17368 ? Sl Mar01 7:45 /usr/bin/python
/usr/bin/trytond --config=/etc/trytond.conf --logfile=/var/log/tryton/trytond.log
root 40178 0.0 2.0 576524 34776 pts/4 Sl+ Mar01 0:03 gedit /etc/trytond.conf
root 50332 0.0 0.0 8112 896 pts/6 S+ 10:45 0:00 grep --color=auto
trytond
python is listening on port localhost:8000
root#Tryton:~# netstat -tupan | grep python
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
37312/python
the client shows the "create" button when entering "localhost" and "8000" in "Create profile"
This is so odd.
After resetting the admin password in trytond.conf to the standard "admin" the login worked again.
The "Creating database" info known from version 2.2 was skipped, the database was created, and in the "Configuring database" dialog a password was asked again (without hint which one), and it turned out to be the local database admin password (means the password created for the admin user of the newly created database).
Somewhat strange, but seems to work locally.
However, no connection via internet yet.
Internet connection solved as well.
It turns out in the end that the documentation for Ubuntu installation (on https://code.google.com/p/tryton/wiki/InstallationOnUbuntu), that currently refers the user to Debian installation, would benefit hugely from having the additional detail given in the installation for e.g. Gentoo, cause they have the actual working config file complete with postgre server settings, which was the decisive point in the end.
See http://wiki.gentoo.org/wiki/Tryton.
I already had
# Activate the json-rpc protocol
jsonrpc = localhost:8000
And after adding this, it worked like a charm:
Configure the database connection
## Note: Only databases owned by db_user will be displayed in the connection dialog
## of the Tryton client. db_user must have create permission for new databases
## to be able to use automatic database creation with the Tryton client.
db_host = localhost
db_port = 5432
db_user = postgres
db_password = postgrsqlpassword
db_minconn = 1
db_maxconn = 64
In my case, I have tryton as database user, some instructions prefer this, obviously for security reasons. By using postgres (the built-in master administrator for PostgreSQL) as database user, you can circumvent having to add the tryton role to postgres (the standard package install with apt-get on Ubuntu adds that automatically anyway iirc).
I'm trying to start a Django app to be hosted on GAE, using CloudSQL. Locally, I'm on Mac OSX Maverics, working within a virtualenv (via virtualenvwrapper).
After installing the GAE SDK for Python, I started my virtual environment, installed Django 1.5 from /usr/local/google_appengine/lib/django-1.5/
Also, on appengine.google.com I created a new app, and connected a CloudSQL instance to it (enable billing).
I'm able to create a new Django project, e.g. django-admin.py startproject test01, then I edit its settings.py to change the DATABASES definition per Google's instructions, e.g:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/myapp-test01:myapp-db-test01',
'NAME': 'test01',
'USER': 'test01',
}
}
I also added app.yaml to the root of the project folder, per Google's docs:
application: test01
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: django
version: "1.5"
builtins:
- django_wsgi: on
This is where I hit roadblocks.
First: What exactly should be entered into the DATABASES for NAME and USER fields? The docs do not go into any detail.
Second, when I run: python manage.py syncdb to initialize the app, I get:
OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/desgn-test-01:db-test-01' (2)")
I do have MySQL installed, via brew install mysql (although I didn't do that inside the virtual environment), and I also have MySQL-python.
I'm new to GAE and fairly inexperienced with setting up databases, so I'm not sure what do try next. I'm not sure if the issue is with my local MySQL, or the CloudSQL connection settings?
(A more general Django on GAE question: What is the workflow exactly? If I get the connection to work, does it mean that I am using CloudSQL even when developing my Django app locally? How do I subsequently "push" the app to the AppEngine, or make updates? I'm assuming this is done with the Launcher but what is the correlation between creating (adding) an app using the appengine.google.com dashboard, versus adding a new app in the local launcher? Quite confused by this -- are these two one and the same app, need to have identical names, or..?)
Looks like at the time, you were missing the password field as well...
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test01',
'USER': 'test01',
'PASSWORD': '[password]',
'HOST': '/cloudsql/myapp-test01:myapp-db-test01',
'PORT': '3306',
}
Using the GUI for Cloud SQL, you can always add new Super Admin level users to the Cloud SQL instance in case you're unsure what user to use as well.
I've been trying to set up my Django project with MAMP for hours,, but still having problem understanding what's going on..
So what I've been doing is:
-First, obviously I installed all the necessary packages (ex. mysql, mysql-python, etc)
-I changed the MAMP's Apache Document Root to Django project folder (/MyDjangoProjects/Sample_Project/)
-I changed the Sample_Project's setting.py to:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'samleprojectdb',
'USER': 'root',
'PASSWORD': 'password1',
'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
'PORT': '',
}
}
-Finally, I ran the Apache and MySQL servers with MAMP and navigated localhost:8888
So I guess basically theses are all the necessary steps that I need to take...
I expected that navigating the page localhost:8888 will direct to my project's main page view (index.html), as I configured in urls.py. However, it just opens an "Index of /" page containing the directories and python files in my local directory. I know MAMP is intended to be used with PHP and to look for index.php, but I thought it should work with Django projects as well..
1. Is there something else I need to do to test Django projects with MAMP??? Thanks...
2. Also, where is the database file "sampleprojectdb" created???? When I used sqlite instead of mysql, the database file was automatically created in the project directory when I ran "python manage.py syncdb"
The host expects the address of the machine that runs the mysql server,like localhost or an IP of the system that runs the DB server.
Also,Use blank for localhost..
About where the database is created,if you mean the files,they are at /var/lib/mysql,but they wont be of much use.syncdb creates the database with the specified configuration.
Also, to run django with apache you will have to setup apache to run the wsgi daemon.
You can try your application using the development server by python manage.py runserver