How to activate mysqldb for Django in virtualenv - python

OK. So I've been treading on the thin edge of madness trying to get a Python virtualenv with Django set up. Tried a couple of different tutorials, first on Mac and then on Linux (Ubuntu), and always get as far as installing the Django package, and then I try and set up the database and everything just melts down. At first I was getting a lot of "mysql_config not found" and architecture compatibility errors (which was when I moved over to trying it on Linux)...now I think I've finally gotten it installed and not conflicting with anything and I don't know what to do next. I'm supposed to edit Django's settings file with the database info (name, UN, PW, and port), and I don't know where to look for this information.
So...my questions:
Is MySQL automatically running on Ubuntu if it is installed? If not, how do I turn it on?
Where do I edit databases? I'm a PHP person in general and this is early days with my forays into Python...I've generally done most of my database management through PHPMyAdmin...I know there's a command line for MySQL and I'd be able to use it but I don't know how to turn it on.
How do I find out what port MySQL is running on?
Again, this is an install in a virtualenv, if that makes any difference to the answers. I apologize if this is a totally noobish question but all the Django setup tutorials I've found seem to just assume I know this step.
Thanks much for any help!

1- mysql not installed on ubuntu by default, if you need to start mysql on the boot try:
chkconfig mysql on
2- mysql has a advanced commandline. just try in terminal:
mysql
use DB;
SELECT * FROM tbl1;
3- mysql runing on port 3306. and you can find port by this:
netstat -tnlp | grep mysql
finally you must be look at: Using PIP in a virtual environment, how do I install MySQL-python

Related

mysql.connector.errors.NotSupportedError: Authentication plugin 'mysql_native_password' is not supported only with pyinstaller exe

I am fighting to find a solution for my problem:
When I start my Python application in my IDE, the database connection is working fine. But when I build an exe with pyinstaller with the following command python3 -m PyInstaller .\home.py and start the application and trigger the connection to the db it gives me the following error:
Previously I had the same error with "caching_sha2_password" instead of "mysql_native_password", then I changed the db plugin to "mysql_native_password" but it still doesn't work in the exe.
My database is running in a Docker Container. The root user, which I use for the connection has also mysql_native_password as the authentication plugin.
However, somehow the connection to the db works every time when I start my application from my IDE. This problem only occurs, after I have exported my application into an exe with pyinstaller.
The connection to the db looks like this:
mysql.connector.connect(
host="localhost",
user="user",
passwd="password",
database="db_name"
)
And yes, I have already checked, that I only have mysql-connector-python installed.
I would be very glad if you could help me out, as this is the final step of my application to be ready for shipment.
Thank you in advance!
After a lot of stress, I decided to install an older version of mysql-connector-python from this site https://downloads.mysql.com/archives/c-python/
I installed the 8.0.20 and for now, working.
test later and verify.
I had this same bug for weeks.
The only difference with you is that I didn't use pyinstaller, but the CX_Freeze.
After I could not find an answer for my problem, I just switched to Postgres and used the corresponding Python driver. Now it works!
When the .exe file is created "caching_sha2_password" is not found...you have to turn debug mode on when creating the .exe file, then you will see the error message.
So the way to resolve the issue is to import "caching_sha2_password" explicitly in your python script, like so:
from mysql.connector.plugins import caching_sha2_password

DPI-1047 error on connecting to Oracle Database in Django

i am trying to connect my oracle 11g database to django but it didn't connect it show some error like
return Database.connect(
django.db.utils.DatabaseError: DPI-1047: Cannot locate a 32-bit Oracle Client library: "C:\oraclexe\app\oracle\product\11.2.0\server\bin\oci.dll is not the correct architecture". See https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html for help
i sucessfully install 32 bit oracle client library but it still shows same error.
i am new to django and this error pops up when i use command python manage.py makemigrations it didn't create migration instead it shows this error.
it would be pleasure if someone helps me.
thankyou :)
The error is because you have a 64-bit Oracle Database installed, and its libraries are first in PATH so Python cx_Oracle tries to load them. Unfortunately your Python is 32-bit so there is a clash, which is shown by the error.
You choices are to set PATH to have your 32-bit Oracle client libraries first when you run Python. You probably don't want to do this globally since that might affect other Oracle DB tools, so you would need to do it in a cmd terminal, or set up a script that sets PATH and then calls python. You would call your new script anytime you wanted to run Python.
Overall, it's probably easier to uninstall Python, and install a 64-bit Python.

Failed to write data to connection Adress (neo4j python

I use the neo4j python driver to write to my database.
I have my neo4j DB setup and was using ita few days ago without any issues.
Today i run my code and i get the following error:
Failed to write data to connection Address(host='localhost',
port=7687) (Address(host='xxx.x.x.x', port=7687));
("0; 'Underlying socket connection gone (_ssl.c:xxxx)'")
When i check via the browser and execute MATCH (n) RETURN n, it appears that all my querys still get executed bc i can find nodes in the database.
I shut my pc down, reinstalled neo4j and basically everything else.
(Its not only for CREATE statements but also for match statemenets)
Adding this at the end of the script worked for me.
db.driver.close()
Asusming you're using this driver, I suspect it might be related to this bug in neo4j-python-driver. It looks like their latest version fixes the bug, according to comments in the thread, but if not, maybe just downgrade back to whatever you were running before, and you should be fine.
It's usually a good idea to lock down your dependencies to avoid problems like this. Have a look at tools like pipenv or poetry if you're not familiar with them, they should save you a few headaches.
I'm uncertain where the issue lies, but the solve it to downgrade to python driver versions:
neo4j: 1.72
neobolt: 1.75
neotime: 1.75

cx_Oracle.DatabaseError: ORA-12541: TNS:no listener

I want to learn how to work with an Oracle Database using Python. If I understand correctly, you can use Oracle Instant Client to connect to an Oracle Database remotely, but I cannot connect. I suspect the issue is that I don't know what arguments to use for the localhost/instance combo. I believe localhost is simply my machine name, or it may be literally 'localhost' which I have tried, but I don't know how and can't find help to tell me how to locate the service name for the database instance.
In a prompt I opened python, imported cx_Oracle and used 'Easy Connect String' as specified in this sample code, using either "(my machine name)/orclpdb" or literally "localhost/orclpdb" for DEFAULT_CONNECT_STRING.
The sample code creates a variable MAIN_CONNECT_STRING which I used in a command prompt to attempt to connect to the remote database:
cnxn = cx_Oracle.connect(MAIN_CONNECT_STRING)
cx_Oracle.DatabaseError: ORA-12541: TNS:no listener
I find answers that seem to be based on this, or others referring to tnsnames.ora, or listener.ora which are files I don't have. I also tried using instantclient-sqlplus-nt-12.2.0.1.0.
Background:
Windows 7
I downloaded cx_Oracle-6.1-cp27-cp27m-win32.whl and
instantclient-basic-nt-12.2.0.1.0.zip
I put the .whl into "C:\Python27\Scripts\"
I used python -m pip
install cx_Oracle --upgrade to install cx_Oracle.
I unzipped the instant client zip and put the child folder here
"C:\instantclient_12_2"
I added ;C:\instantclient_12_2 to the end of PATH.
Maybe you can use the installation instructions found in the
cx_Oracle documentation for Windows, cx_Oracle for Windows
Uninstall first the cx_Oracle you are using then try to follow the instructions found in the link above.

Mac ports Mysql install

I completed my install on Leopard with Mac Ports. I also installed Mysqld via Mac Ports for use with python. I set the password for mysql on mysql start. Everything seemed to be fine except when I invoke mysql-start from the command line now I get this: mysql-start
*****Password:
Starting MySQL
. SUCCESS!
demetrius-fords-macbook-pro-17:~ demet8$
I also get a system que stating:Do you want mysqld to accepting incoming notifications.....
So I kinda think I am activating mysqld, not the actual mysql command interpreter. I can use mysql-stop with no problem to shut the server down. Lastly in the Python interpreter when I run: import MySQLdb I get this:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
I don't think this affects mysqld # all. I don't have the mysql default socket in my path via bash_login. Do I need to do that? thank you....
The command for the client is normally mysql (see MySql docs) However in macports they have appended the major version number so try mysql5
The python error is only a depreciation so can be ignored

Categories