Posts Tagged MySQL
Got an “Error establishing a database connection” in Mac OS X 10.6?
Posted by admin in Mac, Web design & development on September 9, 2010
At some point in the last month (been on holiday mostly) an Apple system update caused MySQL to stop running – all local development sites using MySQL would give the dreaded “Error establishing a database connection” error message. And phpMyAdmin refused to recognize my user/pass credentials.
It seems that Apple has once more made it necessary to explicitly state the MySQL default socket. As stated in this post Mac, WordPress: “Error establishing a database connection” you should edit the mysql.default_socket = line in your php.ini file to read mysql.default_socket = /tmp/mysql.sock .
If you don’t know where to look it’s to be found in an invisible folder at the root of your hard drive called “etc”. To get there go to the menu bar when in the Finder: Go -> Go to Folder… or use this shortcut: [Apple]+[Shift]+G ) then type: /etc .
I’d recommend the excellent (and free) TextWranger to edit the file – as it makes it a breeze by automatically authorizing your changes with a prompt for you admin password when needed.
The change is easy – find the line that reads mysql.default_socket = then add /tmp/mysql.sock to the end.
The line should now read mysql.default_socket = /tmp/mysql.sock
Save the file the restart your Apache webserver by going the System Preferences and stopping, then starting again Web Sharing (found in the Sharing pane).
MAMP stacked (Mac OS X 10.6)
Posted by admin in Web design & development on November 16, 2009
When I moved over to Mac OS X 10.6 last week I found I had to fix my MAMP stack. My old MAMP install didn’t work anymore as unfortunately Marc Liyanage’s excellent PHP package fails in 10.6.
The following instructions are mostly the same as before – except it’s not quite so easy now – if you want more than a base PHP install that is. (I even had another look at the commercial MAMP Pro offering. Nah.) For a simple MAMP stack you really only need to turn on Apple’s PHP package and grab a copy of MySQL. If easy is good for you – jump to 1.5.
But I “like” to have phpMyAdmin and don’t like being warned that I’m missing the mcrypt extension for PHP. If you want mcrypt too – start at #1.
Tools & Requirements:
- You need admin access on your Mac
- Basic understanding of the filesystem and Terminal.app
- If you’ve not got it already grab the wonderful and free editor TextWrangler. The config files that need editing are hidden from normal view – but easily reached by TextWrangler which even has a menu item for that: File / Open hidden… . It also handles authentication beautifully to allow saving without having to manually change permissions to and fro.
1. [extra steps to customise things first eg add mcrypt PHP extension - if you don't need/want it skip past to 1.5.] Go and see Xeon Xai’s blog post Snow Leopard PHP Extensions Installation Tutorial or for a quicker version – go here. These first optional steps to customising your set up (adding PHP extensions and even downgrading PHP from 5.3. to 5.2) has turned out to be more “interesting” than originally perceived and needs post of its own…
1.5 Prepare your php.ini file by duplicating the supplied stock example file and giving it the right name: In Terminal paste this:
sudo cp /private/etc/php.ini.default /private/etc/php.ini
You’ll need to edit the timezone – replace
;date.timezone = with
date.timezone = Europe/Madrid
For other timezones look to the official list here (note the lost semi colon – that’s the comment character)
1.6 Get PHP looking in the right place for MySQL (once you’ve installed it.) …Still editing php.ini find and replace all instances of /var/mysql/mysql.sock with /tmp/mysql.sock . (Why? – well as documented here it seems php.ini is configured for Mac OS X Server’s bundled version of MySQL)
1.7 Start PHP by un-commenting the LoadModule php5_module line in your /etc/apache2/http.conf file.
1.8 Turn Web Sharing (in System Preferences/Sharing) off-and-on again.
2. Get yourself virtualhost.sh from Patrick Gibson. This little shell script will make the process of setting up proper virtual domains on your development server a cinch. I use “.dev” or “.live” as the TLD to prevent any conflict with the live sites. (Although now I’ve started using Git I may just drop the separation between live and development branch domains on my development box. I still put all my sites in my ~/Sites folder though.
3. MySQL
3.1 If you’ve already got another version installed uninstall MySQL from your Mac. NB – this will delete your databases too! But you’ve got those backed up and you want a clean slate:
- sudo rm /usr/local/mysql
- sudo rm -rf /usr/local/mysql*
- sudo rm -rf /Library/StartupItems/MySQLCOM
- sudo rm -rf /Library/PreferencePanes/My*
- edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
- sudo rm -rf /Library/Receipts/mysql*
- sudo rm -rf /Library/Receipts/MySQL*
3.2 Get a MySQL Community Server for the Mac and install it.
4. Give your MySQL root user a password; type the following into the Terminal:
/usr/local/mysql/bin/mysqladmin -u root password sniggle
…if you like sniggle as a password that is.
5. Now you can administer your MySQL server with phpMyAdmin and the root user you’ve just defined. (There are other tools too – eg MySQL Administrator – but I’m used to phpMyAdmin from the hosting packages I use). You may want to virtualhost phpMyAdmin to, for example, “http://mysql/”. Love virtualhost.sh.
6. Then for each [dynamic] site you’ll probably want to add a user and then associate a DB with that user. Do this in phpMyAdmin in one step using the Privileges pane fill in “Add a new User”/then select “Create database with same name and grant all privileges”. Job’s a good ‘un.
Done and not long-winded at-all at-all!
MAMP stacked (Mac OS X 10.5)
Posted by admin in Web design & development on June 5, 2009
UPDATE: I’ve upgraded to Snow Leopard (Mac OS X 10.6) and the following instructions are no longer entirely valid as Marc Liyanage’s PHP package hasn’t been upgraded to work in the Snow.
Want to get MAMP on Mac OS X 10.6?
If you’re on 10.5 you may read on…
Want to roll a MAMP stack of your own to enable proper local web development? Try these steps to getting you own development environment:
1. Swap the Apple package of PHP for Marc Liyanage’s package of PHP for Mac OS X. Read his notes – only takes a minute. His version has useful “extras” like the mcrypt extension that Apple doesn’t include: you’ll want that for phpMyAdmin. (If you’ve already started Apple’s version – you’ll know how to stop it by re-commenting the LoadModule php5_module line in your http.conf file )
2. Get yourself virtualhost.sh from Patrick Gibson. This little shell script will make the process of setting up proper virtual domains on your development server a cinch. I use “.dev” or “.live” as the TLD to prevent any conflict with the live sites. (Although now I’ve started using Git I may just drop the separation between live and development branch domains on my development box. I still put all my sites in my ~/Sites folder though.
3. Get a Mac OS X MySQL package – (not the latest build but v5.0.x) from the good folks at MySQL. If you’ve already got another version installed – here’s how to uninstal MySQL from a Mac (NB – this will delete your databases too!).
4. Give your MySQL root user a password; type the following into the Terminal:
/usr/local/mysql/bin/mysqladmin -u root password sniggle
…if you like sniggle as a passowrd that is.
5. Now you can administer your MySQL server with phpMyAdmin and the root user you’ve just defined. (There are other tools too – eg MySQL Administrator – but I’m used to phpMyAdmin from the hosting packeges I use). You may want to virtualhost phpMyAdmin to, for example, “http://mysql/”. Love virtualhost.sh.
6. Then for each [dynamic] site you’ll probably want to add a user and then associate a DB with that user. Do this in phpMyAdmin in one step using the Privileges pane fill in “Add a new User”/then select “Create database with same name and grant all privileges”. Job’s a good ‘un.
Done and not long-winded at-all at-all!
[Originally posted as a reply in Panic's Coda forum... Lots of love for MAMP Pro - a serious contender - and for just 40€... ]
[MAMP stack] OpenGoo install in Mac OS X 10.5
Posted by admin in Web design & development on April 21, 2009
DON’T READ THIS! READ THIS.
Or How to setup a MAMP Stack on… Mac OS X: a proper write up.
Please disregard the gubbins on this post…
[OK - this was going to be a simple step-by-step account of how to install a particular project management system on a Mac OS X box. That particular project stalled but I learnt a few things about how to get a [M]AMP stack setup to the point a which I can continue… ]
Need a project management package. So far requirements and research lead to Open Goo.
- Download package from OpenGoo.
- Create a MySQL database for it.
- Download and instal PHP My Admin. Nice documentation.
-
- [unstuff it and put the folder into ~/Sites/ , for example]
- virtualhost it
- setup config.inc.php with blowfish key
- fix socket error (?)
- http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html: edit (with TextWrangler of course) /etc/php.ini so that ”mysql.default_socket = /tmp/mysql.sock”
- Fix mcrypt error: “Cannot load mcrypt extension. Please check your PHP configuration”
- Ditch the default OS X PHP install in favour of Marc Liyanage’s packaged instal of PHP for Mac OS X
- If already set up the Apple version of PHP – make sure it’s disabled: ”
LoadModule php5_module“ in/private/etc/apache2/httpd.confshoul commented out - Download and run Marc’s installer from the link above. RTFM mind – but it’s a cinch. The new PHP files will now be in
/usr/local/php5. - Also ditch any previously installed MySQL
- sudo rm /usr/local/mysql
- sudo rm -rf /usr/local/mysql*
- sudo rm -rf /Library/StartupItems/MySQLCOM
- sudo rm -rf /Library/PreferencePanes/My*
- edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
- sudo rm -rf /Library/Receipts/mysql*
- sudo rm -rf /Library/Receipts/MySQL*
- If already set up the Apple version of PHP – make sure it’s disabled: ”
- install to match the PHP package to MySQL 5.0.77
- Create a privileged MySQL user. (Any user may log in without a password to get an anonymous session: “No Privileges”. Mac OS X user account – or _mysql. At this stage log in without a password.)
- Ye-har! Who’d of guessed… Apple’s MySQL documentation was where to find simple instructions for how to give the MySQL root user a password – and hence succeed to log inwith privileges. Terminal command:
/usr/local/mysql/bin/mysqladmin -u root password sniggle. Where sniggle is your choice for a secure password. - For each DB user you should add that user with an MySQL query:
CREATE USER 'user1'@'localhost' IDENTIFIED BY'pass1';
MySQL and phpMyAdmin on Mac 10.5 Leopard
Posted by admin in Web design & development on February 19, 2009
[Update! Lots of gotcha's with using the Apple package of PHP - found that its easier to do a couple of resets as noted here]
Following on from PHP and SSI set-up on a Mac OS X 10.5, now it’s time for MySQL database work. Everything is plain sailing to start with: get and install both MySQL and phpMyAdmin. Then the first snag – phpMyAdmin cannot make a secure connection to MySQL without mcrypt (a PHP encryption extension) – and PHP as shipped with Mac OS X doesn’t come with this.
No solutions here I’m afraid – I’m in a hurry to get the development copy of a site I’m working on ASAP so have just commented out the blowfish and cookies lines in the phpMyAdmin config.inc.php file.
Must get this fixed…
Next problem: default MySQL setup looks in the wrong place for the socket connection. In Leopard the socket sits here /private/tmp/mysql.sock. Edit two lines in the MySQL sections of /etc/php.ini so as to get:
mysql.default_socket = /private/tmp/mysql.sock and
mysqli.default_socket = /private/tmp/mysql.sock
Next problem…