I have a problem with an application I am writing.
Using a file dialog a user picks a file whose values are added to a database, or at least, that's the idea.
Using the mysqldb module I have made all the usual connections at the beginning of the application:
db = MySQLdb.connect(host, user, passwd, database)
cursor = db.cursor()
And then run a piece of code like this:
cursor.execute("INSERT INTO info (key1, code, note) VALUES ('testkey1', 'testcode1', 'testnote1;")
db.commit()
The funny thing is that if I run this on Linux (Ubuntu 13.10) it works perfect without errors or issues.
Yet when I run this on Windows (tested on XP and 7), it doesn't commit at all. And I don't get an error to signal there was a problem.
It's only when I check the database that I discover nothing happened.
Does anyone know why I might be having this compatibility issue?
Just to add: The database on Windows is an EXACT copy of the one on Linux.
It is now solved, it was such a silly mistake, but in case there are any Linux users that NEVER use Windows and do run into this issue, here is the solution.
First ensure that Xampp is installed on the Windows machine.
Ensure the ports are open and MySQL and Apache are installed through the Xampp application.
After this, open PhpMyAdmin and make sure that the permissions of user of the database server match those entered in the python application.
After this, the application will run exactly like on Linux.
I thought installing MySQL along with MySQL Workbench was the right move, but it turns out it uses the Apache's version.
Thanks to everyone who helped.
Related
I have a problem with a compiled python application. The program runs a GUI with a connection to a MySQL database. At first I was getting the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'caching_sha2_password' is not supported
The solution I found here, was to add to the connection command:
auth_plugin = 'mysql_native_password'
And my code looked like this:
conn = mysql.connector.connect(host="localhost", user="root", password="Baelca1", auth_plugin='mysql_native_password')
Now when I compile and run it, I get the error:
mysql.connector.errors.NotSupportedError: Authentication plugin
'mysql_native_password' is not supported.
I'm quite frustrated, I've tried several things and none of them work. I uninstalled and reinstalled mysql-connector-python. I changed the mysql-community server settings. Nothing gets the program to work. The application works fine when I run it from the VSCode terminal but not when I convert it to an executable.
If anyone knows how I can fix it, I would be grateful.
I have a problem that I've been trying to solve for a very long time and it seems like I'm missing something very basic.
I use a Linux server with Anaconda, Oracle client, Pycharm and jupyter-notebook installed.
I use python scripts in which I write and read data to Oracle DB, and I use the Cx_oracle extension.
The server has several users with a personal username for each and each of them has sudo privileges.
I performed all the installations on the server with sudo privileges.
When I try to connect from the server to Oracle DB I connect properly.
When I connect to Python on the server itself, I connect properly to Oracle DB.
When I connect using Pycharm and I define ORACLE_HOME=/OracleTools/19.0.0/ in the environment variables, I connect properly to the Oracle DB.
My problem starts when I want to use jupyter-notebook
When I try to connect to the DB I get the error -
DatabaseError: Error while trying to retrieve text for error ORA-12715
I noticed when I execute os.environ I see that it is defined for me:
ORACLE_HOME: /OracleTools/19.0.0/bin
and should be
/OracleTools/19.0.0
So I changed using command os.environ['ORACLE_HOME'] = '/OracleTools/19.0.0'
Then I get an error:
DatabaseError: ORA-12715: invalid character set specified
And of course this change is not permanently saved ...
If on the server itself I execute the env command both in the private user and in sudo I see ORACLE_HOME: /OracleTools/19.0.0 and not ORACLE_HOME: /OracleTools/19.0.0/bin
My questions:
Where does the data I get in the os.environ command come from?
How can I edit them permanently ?
Is this even the problem I'm having or should I check something else?
I manage to import cx_oracle, which means that there is no problem of expansion
Thanks!
I created a fairly large program written in python, and when I run it locally or on the server as a .py, it does not give me any problem.
However, if I use PyInstaller to create an executable, although it still works locally, it fails when I try to make a LAN connection, as if something in Windows or on the LAN blocks my connection.
I don't understand why in .py everything works perfectly while in .exe the program cannot connect to the SQL Server on the LAN. The program will have to connect to a SQL Server that will run on windows server 2012.
The only thing I haven't tried is trying to sign the program.
It would also be interesting to post the solution somewhere in order to help other people who have the same strange problem.
NOTE: I am using the pymssql library. I also tried using other libraries like pyodbc directly, always the same problem.
Is there a way for python to connect to MS SQL Server using Windows Authentication, even when not running the python app on a windows box?
I'm trying to do this with pymssql, but the examples mostly seem to assume that you're running on windows.
If there is a way to make this connection using some other library, please feel free to suggest, but I do like how pymssql is simple to install and deploy via pip.
I want to connect to 2005/2008 databases, and I'm running Ubuntu 13.04 (but I can upgrade to a later Ubuntu if it makes a difference)
SOLUTION:
It turns out that pymssql can connect to my database via my windows username and password. But to do so, I need to pass the actual username/password like this:
pymssql.connect(host, 'THEDOMAIN\\theusername', 'thepassword', db)
The solution EkoostikMartin provided is still good though (if you do not want to store a password somewhere, which is probably the point to windows auth anyway)
You can use the SQL Server ODBC driver for linux, and set up Kerberos.
See this article - http://technet.microsoft.com/en-us/library/hh568450.aspx
I'm trying to install MYSQLdb on a windows client. The goal is, from the Windows client, run a python script that connects to a MySQL server on a LINUX client. Looking at the setup code (and based on the errors I am getting when I try to run setup.py for mysqldb, it appears that I have to have my own version of MySQL on the windows box. Is there a way (perhaps another module) that will let me accomplish this? I need to have people on multiple boxes run a script that will interact with a MySQL database on a central server.
you could use a pure python implementation of the mysql client like
pymysql
(can be used as a dropin-replacement for MySQLdb by calling pymysql.install_as_MySQLdb())
MySql-Connector
You don't need the entire MySQL database server, only the MySQL client libraries.
It's been a long time since I wrote python db code for windows...but I think something like this should still work.
If you're running the client only on windows machines, install the pywin32 package. This should have an odbc module in it.
Using the windows control / management tools, create an odbc entry for either the user or the system. In that entry, you'll give the connection parameter set a unique name, then select the driver (in this case MySQL), and populate the connection parameters (e.g. host name, etc.) See PyWin32 Documentation for some notes on the odbc module in pywin32.
Also, see this post: Common ways to connect to odbc from python on windows.