MySQL Utilities with MySQL 8 Server - python

As part of our build process, we use the mysqldiff utility (invoked from maven) to validate our database migration scripts by comparing a freshly-built copy of the schema to a version of the schema created from a baseline plus our migration script. This all works fine with MySQL 5.7.
We are looking to upgrade to MySQL 8.0.13. The database user has been configured to use mysql_native_password. When we run our build, we are getting this error from mysqldiff:
ERROR: Authentication plugin 'caching_sha2_password' is not supported
We understand that this error is due to the fact that the utility is using an old version of mysql-python-connector. We also understand that the answer might be as simple as upgrading the connector version, but we don't know how to go about trying that.
The MySQL Utilities can be found at https://github.com/mysql/mysql-utilities.
On Windows 10, we install using the Oracle windows installer. On Amazon Linux, we install with yum.
NOTE:
The MySQL Utilities appear to be based on an embedded python2.7 installation (we do not have standalone python installed on any of the development or build machines).
We do not have python expertise, so detailed steps will be helpful if we are mucking with the embedded python stuff.
We need to solve this problem both on Windows 10 and Amazon Linux.
How do we work around this error so that we can use mysqldiff with a MySQL 8.0.13 server on Windows 10 and Amazon Linux?
If the answer is simply to upgrade the connector, what are the detailed steps for doing that?
Are there server installation/configuration changes we can make to support clients connecting with old drivers?

I have managed to run mysqldiff.py against mysql 8, with some patches:
clone the patched source code and enter its dir:
$ git clone https://github.com/georgexsh/mysql-utilities.git
create a virtualenv and activate it:
$ virtualenv -p python2 venv
$ . venv/bin/activate
install the newer mysql connector:
(venv) $ pip install mysql-connector-python>=8.0
install mysql-utilities to the current virtualenv:
(venv) $ pip install .
now mysqldiff.py is able to run. if you want to run without activate virtualenv, you use its full path:
/path/to/mysql-utilities/venv/bin/mysqldiff.py
steps under windows are mostly the same, except virtualenv activation:
venv\Scripts\activate.bat

I encountered same problem and looked into mysql python connector code and added class for caching_sha2_password. It works for me now.
1. To fix the issue download source code for mysql-python-connector from Mysql official website, then install python (any version).
2. unzip downloaded mysql-python-connector zip file, and inside you will find setup.py
3. Open terminal and type python setup.py install
4. build folder will be created in current folder. Go to build/mysql/ and copy authentication.py file
5. open Mysql Utilities ->> bin ->> library.zip, and find mysql connector- > mysql > authentication.pyc file and delete i and paste authentication.py file you copied earlier.
6. DONE !
If you dont want to mess with it, you can download ready files from this link
Here is the link for files and explanation.
https://github.com/rgaraisayev/mysqldiff

Related

Azure Blob Storage tools not recognizable on M1 Mac in Python VENV

The only line in my code that references blob storage is a simple import statement, but when I uncomment it the entire function crashes. I can't seem to figure out how to get azure-storage-blob to be accessible by the VENV where the function is running.
I've already installed the requisite packages in terminal with Rosetta and am running VS Code with Rosetta as well. The Azure Functions core tools work, but the blob storage tools don't.
I've tried re-installing the package directly in the venv, incorporating the answer from this post to address the "normal site-packages is not writeable" error, but as shown I still get the same result:
(.venv) jonahrotholz#Jonahs-MacBook-Pro Azure w: Rosetta % python3 -m pip install azure-storage-blobDefaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: azure-storage-blob in /Users/jonahrotholz/Library/Python/3.9/lib/python/site-packages (12.14.1)
Any help would be greatly appreciated!
I too faced this issue while working with Windows OS - Python Azure Functions.
But there are many reasons for this issue to occur with respective to User Installation of Python Packages, few of them with their resolutions.
In my previous workarounds, I always use to say to install Python Packages after activating the Virtual Environment and that seems not working in your case.
From the references SO #65808972 and the article given by the user #MingJie-MSFT and the author #BorislavHadzhiev, try with the below steps that will help to fix your issue and run the any of the below commands after activating the Virtual Environment:
python -m pip install <Your_required_python_Package_Name> - For Python Version 2
Replace the python word with python3 or to a specific version python3.x
Append the parameter --user to python package installation command.
If all of the above not worked, then elevate the permissions by replacing the python installer commands like python/python3.x to sudo pip, sudo pip3, sudo python, sudo python3by running the Visual Studio Code IDE as an Administrator mode.
Check the Python interpreter is installed for all of the users or the current user with required permissions and check the python installed path is added to the Environment Variables in the System.

Why does my virtualenv python3 work fine on my local machine but not when I upload the virtualenv to the server?

If I install a virtualenv on my local machine, activate it and try to run python3 then it works fine (with the imported modules). However, after I send it to the live server (using scp and filezilla) it gives the error:
-bash: /<path>/venv4/bin/python3: cannot execute binary file: Exec format error
This also happens with python and python3.8 in the same package.
I have tried reinstalling virtualenv and pipx, recreating the virtualenv and reuploading a few times.
It seems that it can't find the module, as when I activate the virtualenv on the live server and type "which python3" then it shows me the system python3:
/usr/bin/python3
It also does not work if I try to execute the venv's python3 directly, using the full path.
The reason I'm doing this is because the old virtualenv I was using has stopped working because it can't seem to find the installed modules anymore. I'm not sure why.
Any help would be much appreciated.
I believe some pip packages contain more than just python code, and must be compiled. If your host OS is different from your server OS, or you have different libraries installed, the host-compiled code will not be compatible with your server.
Common practice is to create a file with a list of required packages, using something like
pip freeze > requirements.txt
and rebuild the environment on the server, using something like
pip install -r requirements.txt

cx_Oracle does not recognize location of Oracle software installation for installation on Linux

I have been able to successfully install cx_Oracle for use with Python 3.4 on my Windows 8 laptop, and I am now trying to get the same setup (cx_Oracle with Python 3.4) onto a Linux machine. When running the setup.py file from cx_Oracle-5.1.3.tar.gz, I end up with this error:
sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 135, in <module>
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
Following some other answers I looked at (easy_install cx_Oracle (python package) on Windows, https://gist.github.com/jarshwah/3863378) I have installed these 3 instant client rpms:
rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.i386.rpm
And then I set ORACLE_HOME to the folder that they were installed to, which is supposed to help python identify the location of the oracle files so it can do the installation properly.
I still get the same "cannot locate an Oracle software installation" error each time I try to run the setup.py file.
Any idea what I need to do to be able to successfully install cx_oracle?
Update for more info:
echo $ORACLE_HOME returns /instantclient_12_1, which is where the rpm files installed to.
This is the contents of my /instantclient_12_1 directory:
adrci libnnz12.so libsqlplusic.so tnsnames.ora
BASIC_README libocci.so libsqlplus.so tnsnames.ora_andy
genezi libocci.so.12.1 ojdbc6.jar uidrvci
glogin.sql libociei.so ojdbc7.jar xstreams.jar
libclntshcore.so.12.1 libocijdbc12.so sdk
libclntsh.so libons.so sqlplus
libclntsh.so.12.1 liboramysql12.so SQLPLUS_README
This is a bit different from the directory I have for my Windows 8 install - that one has .dll and .sym files, like orasql12.dll. Should the Linux version of the instant client install have different files?
Update with partial solution:
I found a solution that installed cx_Oracle properly, but only during that shell instance:
I set these two environment variables:
export ORACLE_HOME=/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
And then I created a Symbolic link:
ln -s libclntsh.so.12.1 libclntsh.so
After that, going to the cx_oracle folder and doing this worked:
python3 setup.py build
python3 setup.py install
For some reason, sudo python3 setup.py install did not work for this.
Update with link to related question:
My next problem is getting the environment variables to persist outside of the shell instance so I don't have to define the environment variables each time. The environment variables I put in profile.d show up when I echo them, but python fails to import cx_oracle properly, and I have to export the environment variables again for some reason. I don't know the proper procedure for posting a different question related to one, so I opened a new question here:
Linux profile.d environment variables don't work with cx_oracle in Python
Please help me out with this, I feel completely stuck on what to try to make it work. The environment variables show up when I echo them, but they only seem to be functional if I export them again before running the python code.
Updated
As Petriborg suggested, setting LD_RUN_PATH at build time will include the path to the Oracle shared library files in the cx_Oracle shared library that is built during installation. This obviates the need for LD_LIBRARY_PATH as I suggested in my first answer.
For the RPMs that you are using, ORACLE_HOME should be set to /usr/lib/oracle/12.1/client. If you are using pip:
$ export ORACLE_HOME=/usr/lib/oracle/12.1/client
$ export LD_RUN_PATH=/usr/lib/oracle/12.1/client/lib:$LD_RUN_PATH
$ pip install cx_Oracle
$ python -c 'import cx_Oracle; print(cx_Oracle.version)'
5.1.3
Read this documentation for some info on installing and executing applications that use the client libraries.
When I tried installing cx_Oracle with LD_LIBRARY_PATH variable alone in Ubuntu 16.04 with python 2.7.12 and Oracle client 12.1.0.2 pip install fails and is looking for header files which are no more available with Oracle 12.1.0.2 client. It works fine with LD_RUN_PATH

Install MongoDb on RedHat without internet connection

Can anyone explain how to install Mongodb, pyMongo on a RedHat server without an internet connection. Although I have used both before I haave never had to install anything myself.
I have downloaded mongodb-linux-x86_64-rhel62-3.0.0.tgz from Official download page and copied it to the server but what do I do next?
Do I need to modify the .repo file shown in docs and install with yum?
For pyMongo, pip and easy_install are not installed so I'm guessing I need to install from source. The link in the documentation, github.com/mongodb/mongo-python-driver.git, says "Otherwise you can download the project source and do python setup.py install to install." Where do I get the source from (the link doesn't work and where do I put it on the server?
What I did eventually (hope that helps anyone)
is that I had an access to RHEL with internet connection too (made one on google cloud).
So I modified /etc/yum.conf to set keepcache=1 so packages are kept and I installed mongodb for the framework I needed there and then copied the packages from /var/cache/yum/x86_64/server/10gen/packages
It had meta package and four packages, for server, mongos, shell and tools
and installed the latter four, one by one with yum install path/to/package.rpm
and ran service mongod start
and it worked
Installing MongoDB on Linux machine from Binary distribution goes like this
Download desired binary from Mongodb official download page for your respective architecture and distro
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgz
Extract this tar ball
tar -zxvf mongodb-linux-x86_64-3.0.4.tgz
Make directory for mongo binary and copy them their
mkdir -p /mongodb
cp -R -n mongodb-linux-x86_64-3.0.4/ /mongodb
Add this path in PATH variable
export PATH=<PATH_OF_MONGODB_BIN>:$PATH
Installing Pymongo assuming you have internet on some system to clone repo of Pymongo from Github
$ git clone git://github.com/mongodb/mongo-python-driver.git pymongo
$ cd pymongo/
$ python setup.py install
You will need atleast on machine where internet is available.

Installing MySQL Python on Mac OS X

Long story short, when I write the following:
sudo easy_install MySQL-python
I get the error
EnvironmentError: mysql_config not found
All right, so there are plenty of threads and the like on how to fix that, so I run this code:
export PATH=$PATH:/usr/local/mysql/bin
Then I rerun my sudo code:
sudo easy_install MySQL-python
Then I get the following error.
Setup script exited with error: command 'llvm-gcc-4.2' failed with exit status 1
Google/Stack Overflow that, and I am told to download a GCC package which I did the other day, 200 MB's or there-abouts and still no fix.
At this point I am lost, they say insanity is doing the same thing over and over while expecting a different result. Well, I've continually run the aforementioned code expecting a different result, so I'm not to far away from going insane.
At this point in my Python career, I am new to this, but I am willing to try pretty much anything to get this up and running.
If it helps I am officially running, Mac OS X 10.7.5, and I do have MAMP installed (is that an issue?)
Also, the other day when I was trying all of this for the first time I installed (reinstalled?) MySQL, so I'm really in a tough spot at this point.
Is there a fix?
I've racked my brain, searched Google, read Stack Overflow, and spent hours trying to figure this out to no avail.
Here's what I would install, especially if you want to use homebrew:
XCode and the command line tools (as suggested by #7stud, #kjti)
Install homebrew
brew install mysql-connector-c
pip install mysql-python
Another option is to use pymysql it is a pure Python client connection to MySQL so you don't have to mess around with compiling, a good exercise, but it can be frustrating if you are just trying to get something done. pymysql follows the same API as MySQLdb, it can essentially be used as a drop in replacement.
Also, it used to be that MySQLdb, did not work with Python 3, but this may have changed, pymysql didn't have that problem which also induced me to switch, this may have changed though. pymysql can be slower than MySQLdb but you'll have to see if you notice that, it is also under a different license (MIT for pymysql, GPL for MySQLdb)
For Python 3+ the mysql-python library is broken. Instead, use the mysqlclient library. Install with: pip install mysqlclient
It is a fork of mysql-python (also known as MySQLdb) that supports Python 3+
This library talks to the MySQL client's C-interface, and is faster than the pure-python pymysql libray.
Note: you will need the mysql-developer tools installed. An easy way to do this on a Mac is to run
brew install mysql-connector-c
to delegate this task to homebrew. If you are on linux, you can install these via the instructions at the mysqlclient github page.
Install mysql via homebrew, then you can install mysql python via pip.
pip install MySQL-python
It works for me.
I am using OSX -v 10.10.4. The solution above is a quick & easy.
Happening OSX does not have the connection library by default.
First you should install the connector:
brew install mysql-connector-c
Then install with pip mysql
pip install mysql-python
To install PyMySQL
install pip => sudo easy_install pip
install PyMySQL=> sudo easy_install-3.7 pymysql
terminal command to check whether installed or not => pip3 list
or
install PyMySQL=> sudo pip install PyMySQL
terminal command to check whether installed or not => pip3 list
MySQL
The macOS Sierra Public Beta’s didn’t play well with MySQL 5.7.x, but these issues are now resolved by using MySQL 5.7.16
MySQL doesn’t come pre-loaded with macOS Sierra and needs to be dowloaded from the MySQL site.
( https://dev.mysql.com/downloads/mysql/)
The latest version of MySQL 5.7.16 does work with the public release of macOS.
If you already have MySQL 5.7 and you have upgraded OS from El Capitan to Sierra I expect that to be ok, but will be interested if anyone comments on that.
Use the Mac OS X 10.11 (x86, 64-bit), DMG Archive version (works on macOS Sierra).
If you are upgrading from a previous OSX and have an older MySQL version you do not have to update it. One thing with MySQL upgrades always take a data dump of your database in case things go south and before you upgrade to macOS Sierra make sure your MySQL Server is not running.
When downloading you don’t have to sign up, look for » No thanks, just take me to the downloads! – go straight to the download mirrors and download the software from a mirror which is closest to you.
Once downloaded open the .dmg and run the installer.
When it is finished installing you get a dialog box with a temporary mysql root password – that is a MySQL root password not a macOS admin password, copy and paste it so you can use it. But I have found that the temporary password is pretty much useless so we’ll need to change it straight away.
You are also told:
If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.(https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html)
Change the MySQL root password
Note that this is not the same as the root or admin password of macOS – this is a unique password for the mysql root user, use one and remember/jot down somewhere what it is.
Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
if stop throws permission issue
Check the error file first.
tail -f /usr/local/mysql/data/*.err
Do a complete shut down or kill the process. Confirm that no mysql process is running
mysqladmin -uroot shutdown
sudo killall mysqld
ps -ef | grep mysql
Give permisiions
sudo chown -RL root:mysql /usr/local/mysql
sudo chown -RL mysql:mysql /usr/local/mysql/data
chmod -R 755 /usr/local/mysql/data
chmod -R 755 /usr/local/mysql/data/accountname.local.pid
or Right click->get info and change the permission for
/usr/local/mysql/data
/usr/local/mysql/data/Pushparajas-MacBook-Pro.local.pid
Start mysql
sudo mysql.server start
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and log in with a password which is temporary generated:
mysql -u root -p
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass'
;
Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.
\q
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
Starting MySQL
You can then start the MySQL server from the System Preferences or via the command line.
Command line start MySQL.
sudo /usr/local/mysql/support-files/mysql.server start
To find the MySQL version from the terminal, type at the prompt:
/usr/local/mysql/bin/mysql -v -uroot -p
This also puts you in to a shell interactive dialogue with mySQL, type \q to exit.
After installation, in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path, (optional step) this is done in your “.bash_profile” file in your home directory, if you don’t have that file just create it using vi or nano:
cd ; nano .bash_profile
export PATH="/usr/local/mysql/bin:$PATH"
The first command brings you to your home directory and opens the .bash_profile file or creates a new one if it doesn’t exist, then add in the line above which adds the mysql binary path to commands that you can run. Exit the file with type “control + x” and when prompted save the change by typing “y”. Last thing to do here is to reload the shell for the above to work straight away.
source ~/.bash_profile
mysql -v
You will get the version number again, just type “q” to exit.
Fix the 2002 MySQL Socket error
Fix the looming 2002 socket error – which is linking where MySQL places the socket and where macOS thinks it should be, MySQL puts it in /tmp and macOS looks for it in /var/mysql the socket is a type of file that allows mysql client/server communication.
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
phpMyAdmin
uncomment below line in httpd.conf file
LoadModule php7_module libexec/apache2/libphp7.so
First fix the 2002 socket error if you haven’t done so from the MySQL section-
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Download phpMyAdmin, (https://www.phpmyadmin.net/downloads/) the zip English package will suit a lot of users, then unzip it and move the folder with its contents into the document root level(~/Sites/) renaming folder to ‘phpmyadmin’.
Make the config folder
mkdir ~/Sites/phpmyadmin/config
Change the permissions
chmod o+w ~/Sites/phpmyadmin/config
Run the set up in the browser
http://localhost/~username/phpmyadmin/setup/ or http://localhost/phpmyadmin/setup/
You need to create a new localhost mysql server connection, click new server.
Switch to the Authentication tab and set the local mysql root user and the password.
Add in the username “root” (maybe already populated, add in the password that you set up earlier for the MySQL root user set up, click on save and you are returned to the previous screen.
(This is not the macOS Admin or root password – it is the MySQL root user).
Make sure you click on save, then a config.inc.php is now in the /config directory of phpmyadmin directory, move this file to the root level of /phpmyadmin and then remove the now empty /config directory.
In the latest phpmyadmin, download the config.inc.php and place in phpmyadmin directory.
If you want to setup new server move config.inc.php to some location and try http://localhost/~username/phpmyadmin/setup
Now going to http://localhost/~username/phpmyadmin/ will now allow you to interact with your MySQL databases.
To upgrade phpmyadmin just download the latest version and copy the older ‘config.inc.php‘ from the existing directory into the new folder and replace – backup the older one just in case.
Permissions
To run a website with no permission issues it is best to set the web root and its contents to be writeable by all, since it’s a local development it shouldn’t be a security issue.
Lets say that you have a site in the User Sites folder at the following location ~/Sites/testsite you would set it to be writeable like so:
sudo chmod -R a+w ~/Sites/testsite
If you are concerned about security then instead of making it world writeable you can set the owner to be Apache _www but when working on files you would have to authenticate more as admin you are “not” the owner, you would do this like so:
sudo chown -R _www ~/Sites/testsite
This will set the contents recursively to be owned by the Apache user.
If you had the website stored at the System level Document root at say ~/Sites/testsite then it would have to be the latter:
sudo chown -R _www ~/Sites/testsite
Another easier way to do this if you have a one user workstation is to change the Apache web user from _www to your account.
That’s it! You now have the native AMP stack running on top of macOS Sierra.
Ref Link - https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/#ssu
On Mojave, I ran into errors with finding the SSL libraries, here's what finally worked without having to modify mysql_config:
sudo pip install MySQL-Python --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib"
Hopefully that will save someone a few hours of heartache
It's time to be a big boy and install from source. Try this:
1) Download the MySQL-python-1.X.X.tar.gz file(by default will go to your Downloads directory)
2) Open a Terminal window and cd to the Downloads directory.
3) Unzip the file you downloaded:
~/Downloads$ tar xfvz MySQL-python-1.X.X.tar.gz
That will create a directory inside your Downloads directory called MySQL-python
4) cd into the newly created directory.
5) Typically, you just open the file called README or INSTALL and follow the instructions--but generally to install a python module all you do is:
$ sudo python setup.py install
If you care to look, there should be a file called setup.py inside your newly created MySQL-python directory, and you are invoking that program to install the module.
Also note that this:
export PATH=$PATH:/usr/local/mysql/bin
is not permanent if you did that on the command line. You need to put that line in a file called .bashrc in your home directory (~/ or equivalently /Users/YOUR_USER_NAME). To see if .bashrc already exists(it's a hidden file), issue the command:
$ ls -al
and look for .bashrc. If .bashrc doesn't exist, then create it.
As others mentioned before me....getting Python to work with MySQL on a Mac is a ?##$#&%^!! nightmare.
Installed Django framework on Mac OS 10.7.5 initially from the original Django website and when the MySQLdb didn't work, and after many hours googling and trying solutions from SO, I have installed the Django stack from BitNami http://bitnami.com/stack/django
Still, got the issues mentioned above and then some more...
What helped me eventually is what Josh recommends on his blog: http://joshbranchaud.com/blog/2013/02/10/Errors-While-Setting-Up-Django.html
Now Python 2.7 is finally connected to MySQL 5.5
The issue you are having is that the gcc compiler is not installed on your Mac. It will be installed if you have installed XCode. You will have to download gcc complier and install it manually. Follow the below link and download it -
https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.7-v2.pkg
I once had this problem installing Ruby 1.9 and I had to compile ruby for myself because Mountain Lion wasn't supported at that time. After installing the package, verify the install by the command gcc.
I am using Python 2.7.11 :: Anaconda 2.3.0 (x86_64) on Mac OS X 10.11.4 15E65.
You may want to follow the steps below:
Install homebrew
Open a terminal and run: brew install mysql-connector-c
pip install mysql-python
Then the Anaconda will have the mysql-python installed and you can start with MySQLdb then.
Good luck. Thanks.
Above all, I can't solve it. But I add file to /usr/local/include solve it.
https://github.com/peterlee0304/MySQL-Python/blob/master/my_config.h
In /usr/local/include, add a my_config.h file.
Then pip install MySQL-Python
Solve it!
What worked for me is:
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysql-python
the below may be help.
brew install mysql-connector-c
CFLAGS =-I/usr/local/Cellar/mysql-connector-c/6.1.11/include pip install MySQL-python
brew unlink mysql-connector-c
I used PyMySQL instead and its working fine!
sudo easy_install-3.7 pymysql

Categories

Resources