MacPorts has a port for MySQLdb (py-mysql and variants). If Homebrew has a 'formula', I can't find it, but a pip install should work once you have compatible versions of Python and MySQL. The hard way The hard part about the Mac is, there are three architectures you could be building for: PowerPC, Intel 32-bit, and Intel 64-bit. 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. The official home of the Python Programming Language. While Javascript is not essential for this website, your interaction with the content will be limited. The MySQL server is installed on the Mac, but it does not load by default. Start MySQL by clicking Start using the MySQL Preference Pane, which was installed during the default installation. You can configure MySQL to automatically start when you turn on your computer using the MySQL Preference Pane.
Active2 years, 3 months ago
I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is
sh: mysql_config: not found Could someone advice me on what to do?
user618677
user618677user618677
1,89855 gold badges1717 silver badges2121 bronze badges
7 Answers
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:
If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found
Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html
To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:
Community♦
GlaslosGlaslos
2,20211 gold badge1515 silver badges2828 bronze badges
You have 2 options, as described bellow:
Distribution package like Glaslos suggested:
In this case you can't use virtualenv no-site-packages (default option)but must use:
Use clean virtualenv and build your own python-mysql package.
First create virtualenv:
Then install build dependencies:
Now you can install python-mysql
NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)
Kris Hollenbeck
13.1k1818 gold badges5454 silver badges9191 bronze badges
Luka MarinkoLuka Marinko
1,63222 gold badges1111 silver badges1414 bronze badges
samayo
10.9k1212 gold badges6161 silver badges9191 bronze badges
MayankMayank
3,69411 gold badge1111 silver badges1515 bronze badges
Reread the error message. It says:
sh: mysql_config: not found
If you are on Ubuntu Natty, gsbabilgsbabil
mysql_config belongs to package libmysqlclient-dev
5,51411 gold badge2020 silver badges2525 bronze badges
this worked for me on python 3
pip install mysqlclient
JouhaynaJouhayna
10.9k1212 gold badges6161 silver badges9191 bronze badges
xiecheng127xiecheng127
Python or Python3 with MySQL, you will need these. These libraries use MySQL's connector for C and Python (you need the C libraries installed as well), which overcome some of the limitations of the mysqldb libraries.
David Peterson HarveyDavid Peterson Harvey
16922 gold badges33 silver badges1414 bronze badges
Not the answer you're looking for? Browse other questions tagged pythonmysql or ask your own question.
Active9 months ago
Long story short, when I write the following:
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:
Then I rerun my sudo code:
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.
Peter Mortensen
14.5k1919 gold badges8989 silver badges118118 bronze badges
Peter FotiPeter Foti
4,60944 gold badges2727 silver badges4141 bronze badges
13 Answers
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)
Paul JoiremanPaul Joireman
Here's what I would install, especially if you want to use homebrew:
6,45544 gold badges2828 silver badges4646 bronze badges
Install mysql via homebrew, then you can install mysql python via pip.
It works for me.
Don Roby
37.2k66 gold badges7878 silver badges101101 bronze badges
JudeJude
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
to delegate this task to homebrew. If you are on linux, you can install these via the instructions at the mysqlclient github page.
The AelfinnThe Aelfinn
5,65811 gold badge2828 silver badges3232 bronze badges
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:
Then install with pip mysql
Community♦
Mac Os Install Mysql-python
jasmo2jasmo2
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:
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:
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:
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:
Mysql Python Install Mac
and look for .bashrc. If .bashrc doesn't exist, then create it.
Smart card driver free download. Your old drivers can be backed up and restored if you encounter any problems. Or, try the option instead.Once you have downloaded the new driver, next you must remove the current driver if it is installed. You’ll need novice to beginner level computer skills to use this method. If you cannot find the right driver for your Card Reader, you can and we will find it for you.
7stud7stud
33.5k1111 gold badges7171 silver badges9191 bronze badges
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
TorenToren
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 -
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 .
Install Python Mysql ConnectorChanChan
2,05333 gold badges2121 silver badges4141 bronze badges
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:
Then the Anaconda will have the mysql-python installed and you can start with MySQLdb then.
Good luck. Thanks.
HelloObamamaHelloObamama
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
if stop throws permission issue
Check the error file first.
Do a complete shut down or kill the process. Confirm that no mysql process is running
Give permisiions
Start mysql
Start it in safe mode:
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:
;Change the lowercase ‘MyNewPass’ to what you want – and keep the single quotes.
Start MySQL
Starting MySQL
You can then start the MySQL server from the System Preferences or via the command line.
Command line start MySQL.
Download Mysql
To find the MySQL version from the terminal, type at the prompt:
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:
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.
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.
phpMyAdmin
uncomment below line in httpd.conf file
First fix the 2002 socket error if you haven’t done so from the MySQL section-
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
Change the permissions
Run the set up in the browserhttp://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
Mac Install Mysql Python Mac
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:
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:
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:
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
Pushpa RajaPushpa Raja
Golden ThumbGolden Thumb
On Mojave, I ran into errors with finding the SSL libraries, here's what finally worked without having to modify
mysql_config :
Hopefully that will save someone a few hours of heartache
Alex WAlex W
Mac Did You Install Mysqlclient Or Mysql-python
29.2k77 gold badges7575 silver badges8888 bronze badges
user10348581user10348581
Not the answer you're looking for? Browse other questions tagged pythonmysqlmacos or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |