Install mysqldb on snow leopard - python

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tell me where I need to start and what steps I need to follew I would be most grateful.
Thanks

On MAC OS X 10.6, Install the package as usual. The dynamic import error occurs because of wrong DYLD path. Export the path and open up a python terminal.
$ sudo python setup.py clean
$ sudo python setup.py build
$ sudo python setup.py install
$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
$python
import MySQLdb
Now import MySQLdb should work fine.
You may also want to manually remove the build folder, before build and install. The clean command does not do a proper task of cleaning up the build files.

I'd recomend installing macports (latest svn trunk) and installing mysql from there.
sudo port install mysql5-server
Download the MySQL-python-1.2.2 source
make sure /opt/local/lib/mysql5/bin is in your path or edit site.cfg to include:
mysql_config = /opt/local/lib/mysql5/bin/mysql_config
Comment out line 38 of _mysql.c
// #define uint unsigned int
Then run:
sudo python setup.py install
should be all good.

[Partial Answer]
You'll have more fun pulling out your teeth. MySQL/Django/Mac is a disaster. This is the farthest I've gotten:
Get MySQLDB 1.2.3
Go into that and modify setup_posix.py:
Change:
mysql_config.path = "mysql_config"
To (depending on the version number of your MySQL):
mysql_config.path = "/usr/local/mysql-5.1.34-osx10.5-x86_64/bin/mysql_config"
python setup.py build
python setup.py install
Here's a good article

First and foremost, make sure that XCode is installed. Without XCode, many pieces of the built-in Apache2 server important to developers are missing; most notably, the GNU Compiler Collection, which I would think to be requisite for MySQL bindings.

One of the key things here is to make sure you're running both MySQL and the Python adaptor in 64 bit. The default Python 2.6.1 install on Snow Leopard is 64 bit so you must install MySQL in 64 bit and build the MySQLdb adapter in 64 bit.
Make sure you have the latest Xcode installed
Install 64-bit MySQL from DMG - http://dev.mysql.com/downloads/mirror.php?id=401941#mirrors
Download MySQL-python-1.2.3 from http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Extract and make the following edit to site.cfg:
mysql_config = /usr/local/mysql/bin/mysql_config
Then from your terminal run
ARCHFLAGS="-arch x86_64" python setup.py build
sudo python setup.py install
You should then open a Python shell and type:
import MySQLdb
If you don't get any errors you're golden.

Xcode was installed.
Follow these instructions for setting up apache/php/mysql:
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
I installed the free 32-bit version of EPD (this is optional but I wanted numpy/scipy).
Make sure you have these lines in your ~/.profile (the second line is only if you installed EPD):
export PATH=/usr/local/mysql/bin/:/usr/local/bin:/usr/local/sbin:$PATH
export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
Downloaded mysqldb and run:
python setup.py build
sudo python setup.py install
Install the official release of Django or web2py. Everything worked after that. You can try the "Writing Your First Django App, Part 1" to test it out where in settings.py use:
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'Django Polls'
DATABASE_USER = '*****'
DATABASE_PASSWORD = '*****'
DATABASE_HOST = '127.0.0.1'
DATABASE_PORT = '3306'
I also use Navicat Lite and Sequel Pro for working with MySQL.
Pydev is a nice IDE to use with Django.

Install the newest 64bit DMG version of MySQL. Remember to backup your databases if you already have MySQL installed.
enter this line in terminal:
sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
Edit the file setup_posix in the mysql-python installation directory.
Change the line
mysql_config.path = "mysql_config"
to
mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Myslq-Python needs a 64bit Version of Python. The new Python 2.7 64bit version creates an alias in /usr/local/bin/python.
Enter the following lines in the mysql-python folder
sudo /usr/local/bin/python setup.py clean
sudo ARCHFLAGS="-arch x86_64"
sudo /usr/local/bin/python setup.py build
sudo /usr/local/bin/python setup.py install
And finally try it out:
python
import MySQLdb

You could make your life a lot easier (especially on Lion) by just installing Mariadb instead:
http://mariadb.org/
It's a drop-in replacement for MySQL and is plug&play on OSX. The only thing you don't get is the MySQL system setting.

Related

missing module sqlite3 on python 3.5 [duplicate]

I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:
File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
Looking at the Python install, it gives the same error:
Python 2.5.2 (r252:60911, May 12 2009, 07:46:31)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?
It seems your makefile didn't include the appropriate .so file. You can correct this problem with the steps below:
Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install
Note
The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.
I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.
I had the same problem with Python 3.5 on Ubuntu while using pyenv.
If you're installing the python using pyenv, it's listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version with
pyenv install <python-version>
Then recreate virtualenv if needed.
my python is build from source, the cause is missing options when exec configure
python version:3.7.4
./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install
fixed
This is what I did to get it to work.
I am using pythonbrew(which is using pip) with python 2.7.5 installed.
I first did what Zubair(above) said and ran this command:
sudo apt-get install libsqlite3-dev
Then I ran this command:
pip install pysqlite
This fixed the database problem and I got confirmation of this when I ran:
python manager.py syncdb
Install the sqlite-devel package:
yum install sqlite-devel -y
Recompile python from the source:
./configure
make
make altinstall
I found lots of people meet this problem because the Multi-version Python,
on my own vps (cent os 7 x64), I solved it in this way:
Find the file "_sqlite3.so"
find / -name _sqlite3.so
out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so
Find the dir of python Standard library you want to use,
for me /usr/local/lib/python3.6/lib-dynload
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.
For Python 3.7.8 with Redhat 7 or Centos 7.
Install sqlite-devel
$ yum install sqlite-devel
Compile and install Python3 with sqllite extensions
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install
My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.
Try the following:
find /usr/local -name _sqlite3.so
If the file isn't found, something may be wrong with your Python installation. If it is, make sure the path it's installed to is in the Python path. In the Python shell,
import sys
print sys.path
In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.
I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:
Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:
def sqlite_incdir:
sqlite_dirs_to_check = [
os.path.join(sqlite_incdir, '..', 'lib64'),
os.path.join(sqlite_incdir, '..', 'lib'),
os.path.join(sqlite_incdir, '..', '..', 'lib64'),
os.path.join(sqlite_incdir, '..', '..', 'lib'),
'/usr/lib/x86_64-linux-gnu/'
]
With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same "ImportError: No module named _sqlite3" whe running "import sqlite3".
So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).
Voila! SQLite3 support now works.
This worked for me in Redhat Centos 6.5:
yum install sqlite-devel
pip install pysqlite
sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.
Uninstall existing python:
sudo apt-get remove --purge python3.6
Install python3.6:
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
Is the python-pysqlite2 package installed?
sudo apt-get install python-pysqlite2
Checking your settings.py file.
Did you not just write "sqlite" instead of "sqlite3" for the database engine?
Putting answer for anyone who lands on this page searching for a solution for Windows OS:
You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.
pip install pysqlite3
pip install db-sqlite3
For me the issue was with DLL file of sqlite3.
Solution:
I took DLL file from sqlite site. This might vary based on your
version of python installation.
I pasted it in the DLL directory of
the env. for me it was "C:\Anaconda\Lib\DLLs", but check for yours.
I have the problem in FreeBSD 8.1:
- No module named _sqlite3 -
It is solved by stand the port ----------
/usr/ports/databases/py-sqlite3
after this one can see:
OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'
you must be in centos or redhat and compile python yourself,
it is python‘s bug
do this in your python source code dir and do this below
curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1
I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:
Install SQLite3 from scratch with the proper prefix
Make clean my Python Installation
Run Make install to reinstall Python
As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:
http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html
I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.
i got the same problem, nothing worked for me from the above ans
but now i fixed it by
just remove python.pip and sqlite3 and reinstall
sudo apt-get remove python.pip
sudo apt-get remove sqlite3
now install it again
sudo apt-get install python.pip
sudo apt-get install sqlite3
in my case while installing sqlite3 again it showed some error
then i typed
sqlite3
on terminal to check if it was removed or not and it started unpacking it
once the sqlite3 is installed
fireup terminal and write
sqlite3
database.db (to create a database)
i'm sure this will definately help you
Try installing sqlite like this if you are using FreeBSD.
pkg install py27-sqlite3-2.7.10_6
I had the same problem after installing Python 3.8.11 using asdf
To fix the issue:
I had to install libsqlite3-dev
sudo apt-get install libsqlite3-dev
Then uninstall Python via asdf
asdf uninstall python 3.8.11
And install Python again via asdf
asdf install python 3.8.11
The following worked for Python 3.9 with a virtual environment:
Install the sqlite3 library.
sudo apt-get install libsqlite3-dev
Activate the Python virtual environment.
source env/bin/activate
Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages
mv ./env/lib/python3.9/site-packages/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages/_sqlite3.cpython-39-x86_64-linux-gnu.so
Note, we're renaming 38 to 39 in the file name to support Python 3.9.
Download sqlite3:
wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz
Follow these steps to install:
$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install
I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.
Error I got:
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I resolved it by --enable-loadable-sqlite-extensions=yes
1.) First find your python or python version you used for creating virtual env. I have used python3.8
e.g
$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config python
$ cd /usr/bin
$ls
python3.8
python3.8-config
Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version
ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes
OR
ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions
Now, create your virtual env using that python version
e.g
Go the folder where you want to create the virtual env
$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate
Its done, now you can install packages
I ran into this same problem on a NetBSD server. A missing .so file needed to be installed using pkgin. To identify what package to install, I ran
pkgin search sqlite
which had lots of results, including
...
py38-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2 Python wrapper for SQLite
py38-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22 Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2 Python wrapper for SQLite
py39-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22 Built-in sqlite support for Python 2.5 and up
...
(and other python versions as well). I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case. Running
sudo pkgin install py39-sqlite3-3.9.13nb22
fixed the issue for me.
You need to install pysqlite in your python environment:
$ pip install pysqlite
Try copying _sqlite3.so so that Python can find it.
It should be as simple as:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/
Trust me, try it.

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

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

MySQLdb within python2.5 virtualenv

I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6).
When I import MySQLdb from within python version 2.6 it imports is successfully. When I import MySQLdb from within the python 2.5.5 virtual-env the import fails (because I have installed virtual-env with --no-site-packages). So, I have to install MySQLdb python as a local package (local to virtual-env).
'easy_install MySQL-python' within the virtual env fails. It downloads the MySQL-python-1.2.3.c1.tar.gz/download, but the 'python setup.py build' fails with error. The same problem occurs when building the MySQL outside of virtual-env.
Is the 'python setup.py build' for MySQL-python trying to link to a library (and am I missing some library)? Or is the downloaded code missing some header files (unlikely)?
Thanks.
S.Mark,
If I were to install MySQL header files, would they mess with the existing rpms?
[Sorry, for being redundant. In essence, MySQL is functional on the machine, MySQL-python is functional for python 2.6, but MySQL-python is not functional from virtualenv for python 2.5.5.]
Thank you for trying to help.
# rpm -qa | grep -i mysql
MySQL-python-1.2.3-0.4.c1.fc11.x86_64
perl-DBD-MySQL-4.010-1.fc11.x86_64
mysql-libs-5.1.42-7.fc11.x86_64
mysql-5.1.42-7.fc11.x86_64
php-mysql-5.2.12-1.fc11.x86_64
mysql-server-5.1.42-7.fc11.x86_64
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
_mysql.c:39:26: error: mysqld_error.h: No such file or directory
_mysql.c:40:20: error: errmsg.h: No such file or directory
Please install MySQL header files, probably here
Works! Thanks for all your help.
I installed mysql-devel package (yum install mysql-devel) on the box.
Then did easy_install MySQL-python from within virtual-env (python 2.5.5), and the compilation/installation was successful (with some warnings).
Thanks.
Just to mention for the others that might end up here too,
I solved this error in installing mysql-devel
$ yum install mysql-devel.x86_64
Hope this helps
In case it does not work even after installing mysql-devel package, check the contents of "/usr/include/mysql".
If is empty then its possible that mysql-devel has installed the header files at some pther place, run following command to find
find /usr/include/ -maxdepth 1 -name mysql*
If found, create a symlink like following to fix the problem.
ln -s /usr/include/mysql51 /usr/include/mysql

How to build sqlite for Python 2.4?

I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:
error: command 'gcc' failed with exit status 1
As far as I understood the problems appears because version of my Python is 2.4.3 and SQLite is integrated in Python since 2.5. However, I also found out that it IS possible to build sqlite for Python 2.4 (using some tricks, probably).
Does anybody know how to build sqlite for Python 2.4?
As another option I could try to install higher version of Python. However I do not have root privileges. Does anybody know what will be the easiest way to solve the problem (build SQLite fro Python 2.4, or install newer version of Python)? I have to mention that I would not like to overwrite the old version version of Python.
Thank you in advance.
You can download and install Python to your home directory.
$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install
Then, (if you are using bash) in your .bash_profile do
export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH
Then, source the file to make it available
$ cd
$ source .bash_profile
$ python -V
where python -V will return the python version. If the correct version appears, any packages that you run with Python's setup.py util (assuming the developer followed the correct conventions) will install in ~/opt/lib/python2.x/site-packages directory.
Download pysqlite here, cd into the directory you downloaded to, unpack the tarball:
$ tar xzf pysqlite-2.5.5.tar.gz
then just do (if your permissions are set right for this; may need sudo otherwise):
$ cd pysqlite-2.5.5
$ python2.4 setup.py install
one error does appear in the copious output:
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/pysqlite2/test/py25tests.py", line 48
with self.con:
^
SyntaxError: invalid syntax
since as clearly shown that file is for py 2.5 tests only (with statement not present in 2.4!-). Nevertheless the install is successful:
$ python2.4 -c'import pysqlite2'
$
All this is on Mac OS X 10.5 but using python2.4 separately installed from the system-supplied Python 2.5.
The error you report doesn't tell us much -- maybe you're missing the headers or libraries for sqlite itself? Can you show us other output lines around that single error msg...?
If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your PATH. It seems easier to go that direction than to try to make sqlite work with an old version of Python.
You will also be doing yourself a favor by using a recent version of Python, because you'll have access to the numerous recent improvements in the language.
I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.

Categories

Resources