freebsd + git server + gitweb

November 22nd, 2011 rupert Comments off

1. install git server

$ cd /usr/ports/devel/git
$ make install clean

Note: Include gitweb as an option

2. Modify /etc/rc.conf

git_daemon_enable="YES"
git_daemon_directory="/var/db/git/repo"
git_daemon_flags="--export-all --syslog --enable=receive-pack --listen=ip_address --verbose"

3. Create git user

$ pw user add git
$ passwd git
$ chsh git
Login: git
Password: *******************
Uid [#]: 1002
Gid [# or name]: 1002
Change [month day year]:
Expire [month day year]:
Class:
Home directory: /var/db/git
Shell: /usr/local/bin/git-shell
Full Name: User &
Office Location:
Office Phone:
Home Phone:
Other information:

“git” user would create repositories. We could also add “rupert” to the git group.

pw user mod rupert -G git

4. Let’s create a repository

$ cd /var/db/git/repo
$ sudo mkdir cws-rails.git
$ cd cws-rails.git/
$ sudo git --bare init
Initialized empty Git repository in /var/db/git/repo/cws-rails.git/
$ cd ..
$ ls -l
total 4
drwxr-xr-x  7 root  git  512 Nov 16 12:54 cws-rails.git
drwxrwxr-x  7 git   git  512 Nov 16 11:52 myproject.git
$ sudo chown -Rf git:git cws-rails.git
$ sudo chmod -Rf 775 cws-rails.git

Make sure to change the ownership to git. We also make it writable to the group so users like rupert will have write access.

5. Let’s clone, commit and push
So now in my MBP, i will clone myproject.git, change some file and push.

$ git clone rupert@rupert-bsd:/var/db/git/repo/myproject.git
Cloning into myproject...
Password:
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 12 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (12/12), done.
~/Desktop/myproject[master]% gc -m "Updated CHANGELOG" CHANGELOG 
[master d9fd0f7] Updated CHANGELOG
 1 files changed, 1 insertions(+), 0 deletions(-)
~/Desktop/myproject[master]% git push
Password:
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To rupert@rupert-bsd:/var/db/git/repo/myproject.git
   5d16498..d9fd0f7  master -> master

Note: So that we don’t need to specify the password all the time, generate an ssh-keygen -t rsa for id_rsa.pub and append it to rupert@rupert-bsd:/home/rupert/.ssh/authorized_keys

6. Setup Git, Configure and Restart Apache2

# Copy the gitweb directory to your apache22 directory
$ sudo cp -Rf /usr/local/share/examples/git/gitweb /usr/local/www/apache22/data/
 
# Edit gitweb.cgi to point to your repo
$ vim /usr/local/www/apache22/data/gitweb/gitweb.cgi
our $projectroot = "/var/db/git/repo";
# Allow apache to execute gitweb.cgi
Alias /gitweb /usr/local/www/apache22/data/gitweb
 
<Directory /usr/local/www/apache22/data/gitweb>
  Options FollowSymLinks +ExecCGI
  AddHandler cgi-script .cgi
</Directory>

Browse http://servername/gitweb/gitweb.cgi

Categories: freebsd Tags: ,

freebsd + postgresql-server + plpython + postgis

November 16th, 2011 rupert Comments off

1. Install prerequisites

% cd /usr/ports/textproc/libxml2
% make
% make install

2. Install python

% cd /usr/ports/lang/python26
% make config #opens up blue terminal which allows to choose options
% make
% make install

3. Install

% cd /usr/ports/databases/postgresql90-server
% make
% make install clean

4. Initialize

% vim /etc/rc.conf
postgresql_enable=YES
postgresql_data=/var/db/pgsql
% mkdir /var/db/pgsql
% chown -Rf pgsql:pgsql /var/db/pgsql
% /usr/local/etc/rc.d/postgresql initdb -E utf8

5. Configuration
Allow incoming connections and set the default timezone to ‘UTC’

% vim /var/db/pgsql/postgresql.conf
listen_addresses = '*'     # what IP address(es) to listen on;
 
timezone = 'UTC' #not necessary
% vim /var/db/pgsql/pg_hba.conf
# your network
host    all             all             192.168.10.0/24          trust

6. Start/Stop

% /usr/local/etc/rc.d/postgresql start
% telnet 127.0.0.1 5432

7. Create user. Login as root then switch to pgsql user

% su - pgsql
[root@rupert ~]# su - pgsql
$ psql -d postgres
psql (9.0.6)
Type "help" for help.
 
postgres=# CREATE ROLE rupert WITH LOGIN PASSWORD '**********' SUPERUSER INHERIT CREATEDB CREATEROLE;
CREATE ROLE
postgres=#

8. Install plpython

% /usr/ports/databases/postgresql-plpython
% make
% make install clean

To test if plpython is working properly, we create a testdb and loadup plpythonu and call a plpython function.

[root@rupert ~]# createdb -U rupert testdb
[root@rupert ~]# psql -d testdb -U rupert
psql (9.0.6)
Type "help" for help.
 
testdb=# CREATE PROCEDURAL LANGUAGE 'plpythonu' HANDLER plpython_call_handler;
NOTICE:  using pg_pltemplate information instead of CREATE LANGUAGE parameters
CREATE LANGUAGE
testdb=# create or replace function pyver() returns text as
testdb-# $$
testdb$# import sys
testdb$# return sys.version
testdb$# $$ language 'plpythonu';
CREATE FUNCTION
testdb=# select pyver();
                   pyver                    
--------------------------------------------
 2.6.7 (r267:88850, Feb  6 2012, 13:10:39) +
 [GCC 4.2.1 20070831 patched [FreeBSD]]
(1 row)
 
testdb=#

9. Install postgis

% cd /usr/ports/databases/postgis
% make
% make install

Note that ports should install proj and geos.

10. Create template_postgis

% cd /usr/local/share/postgis
% su - pgsql
$ createdb -E utf8 template_postgis
$ psql -d template_postgis -f postgis.sql
$ psql -d template_postgis -f spatial_ref_sys.sql

11. Install adminpack module

This will eliminate “servers instrument error” when pgAdmin loads up postgres (default) db

% cd /usr/ports/databases/postgresql90-contrib
% make
% make install
% cd /usr/local/share/postgresql/contrib
% su - pgsql
$ psql -U pgsql -d postgres -f adminpack.sql
Categories: postgres Tags: , ,

Nominatim + homebrew on OSX + OSM data + PHP = open sourced reverse geocoder

November 14th, 2011 rupert 3 comments

This installation guide (at the time of writing) was tested on SVN trunk of OSM2PGSQL and running on latest/stable Postgres/Postgis versions on OSX via homebrew.

1. Summary

OSX Snow Leopard
 
OSM2PGSQL: 
Head http://svn.openstreetmap.org/applications/utils/export/osm2pgsql Revision: 27034
Last Changed Author: frederik
Last Changed Rev: 27030
Last Changed Date: 2011-11-09 10:57:49 +1100 (Wed, 09 Nov 2011)
 
POSTGRES: 9.0.4
 
POSTGIS: "POSTGIS="1.5.3" GEOS="3.3.1-CAPI-1.7.1" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.3" USE_STATS" # SELECT POSTGIS_FULL_VERSION();
 
PHP: 5.3.8 (cli) (built: Nov 14 2011 14:41:52) #php -v

2. Installation
Most of the software is installed via homebrew.

# Install homebrew
% /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
 
# Install postgresql
% brew install postgresql
% initdb -E utf8 -D /usr/local/var/postgres
% cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
% launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
% psql -d postgres -f /usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/adminpack.sql
 
# Install postgis
% brew install proj
% brew install geos
% brew install postgis
 
# Create template_postgis_osm
% createdb -E utf8 template_postgis_osm
% psql -d template_postgis_osm -f "/usr/local/Cellar/postgresql/9.0.4/share/postgresql/contrib/pg_trgm.sql"
% psql -d template_postgis_osm -f /usr/local/Cellar/postgis/1.5.3/share/postgis/postgis.sql
% psql -d template_postgis_osm -f /usr/local/Cellar/postgis/1.5.3/share/postgis/spatial_ref_sys.sql
 
# Install osm2pgsql. Can skip this.
# % brew install osm2pgsql

For detail instructions on installing Postgres/Postgis via Homebrew, read this homebrew + postgresql9.0.4 + postgis.1.5.3 + proj4 + geos3.3.1 + osm2pgsql. If you are having problems installing GEOS, then read that link as it shows you how to upgrade GEOS to 3.3.1.

OSM2PGSQL needs GEOS as well. Note that brew only install the osm2pgsql binary. Don’t worry, we will compile this via source later.

3. More Installation.

We need to get PHP installed to run gazetteer http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/

# Install PHP
% brew install php --with-mysql --with-pgsql --with-apache
 
# Hookup with Apache
# Edit httpd.conf to LoadModule
 
# Install PEAR DB
% pear install db

4. OSM2PGSQL
Read this wiki: http://wiki.openstreetmap.org/wiki/Osm2pgsql. Well, we eventually need the whole OSM2PGSQL source as it contains the website (gazetteer).

% svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql osm2pgsql
% cd osm2pgsql
% ./autogen.sh
% ./configure
% make
 
# At this point there should be an osm2pgsql binary.

We need to compile gazetteer for gazetteer.so which is used by gazetteer-functions.sql

gis/osm2pgsql/gazetteer% make clean
gis/osm2pgsql/gazetteer% make 
gis/osm2pgsql/gazetteer% make install
test -z "/usr/local/lib/osm2pgsql" || .././install-sh -c -d "/usr/local/lib/osm2pgsql"
 /bin/sh ../libtool --mode=install /usr/bin/install -c  'gazetteer.la' '/usr/local/lib/osm2pgsql/gazetteer.la'
libtool: install: /usr/bin/install -c .libs/gazetteer.so /usr/local/lib/osm2pgsql/gazetteer.so
libtool: install: /usr/bin/install -c .libs/gazetteer.lai /usr/local/lib/osm2pgsql/gazetteer.la
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/osm2pgsql
 
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution
 
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/share/gazetteer" || .././install-sh -c -d "/usr/local/share/gazetteer"
 /usr/bin/install -c -m 644 'extract_countrynames.sql' '/usr/local/share/gazetteer/extract_countrynames.sql'
 /usr/bin/install -c -m 644 'gazetteer-index.sql' '/usr/local/share/gazetteer/gazetteer-index.sql'
 /usr/bin/install -c -m 644 'gazetteer-loaddata.sql' '/usr/local/share/gazetteer/gazetteer-loaddata.sql'
 /usr/bin/install -c -m 644 'gazetteer-tables.sql' '/usr/local/share/gazetteer/gazetteer-tables.sql'
 /usr/bin/install -c -m 644 'import_country_name.sql' '/usr/local/share/gazetteer/import_country_name.sql'
 /usr/bin/install -c -m 644 'import_country_osm_grid.sql' '/usr/local/share/gazetteer/import_country_osm_grid.sql'
 /usr/bin/install -c -m 644 'import_gb_postcodearea.sql' '/usr/local/share/gazetteer/import_gb_postcodearea.sql'
 /usr/bin/install -c -m 644 'import_gb_postcode.sql' '/usr/local/share/gazetteer/import_gb_postcode.sql'
 /usr/bin/install -c -m 644 'import_specialwords.sql' '/usr/local/share/gazetteer/import_specialwords.sql'
 /usr/bin/install -c -m 644 'import_us_statecounty.sql' '/usr/local/share/gazetteer/import_us_statecounty.sql'
 /usr/bin/install -c -m 644 'import_us_state.sql' '/usr/local/share/gazetteer/import_us_state.sql'
 /usr/bin/install -c -m 644 'import_worldboundaries.sql' '/usr/local/share/gazetteer/import_worldboundaries.sql'
 /usr/bin/install -c -m 644 'gazetteer-functions.sql' '/usr/local/share/gazetteer/gazetteer-functions.sql'

5. Download Data
You can get some regional OSM data from cloudmade. http://downloads.cloudmade.com/oceania/australia_and_new_zealand/australia/victoria

I suggest you download a regional extract prior to downloading/testing with the whole planet-osm. If you don’t believe me that it will take long, you can read http://wiki.openstreetmap.org/wiki/Nominatim/Installation

6. Load and Index Data
Basically, this is the summary of commands taken from http://wiki.openstreetmap.org/wiki/Nominatim/Installation At the time of writing this, I had issues such as “planet_osm_ways” (and several tables) does not exist. So I did a pg_dump and restored the tables afterwards. Be very careful with using the script below, you can comment the indexing part just to speed up on loading and see if you have errors, etc.

DATABASE_NAME=gazetteer_vic
OSM2PGSQL_HOME=/Users/rupert/projects/gis/osm2pgsql
SOURCE_DATA=/Users/rupert/Desktop/australia/victoria.osm
DUMP_DIR=/Users/rupert/Desktop/pg_dumps/streetlookup
 
dropdb $DATABASE_NAME 
#dropuser www-data
 
createdb $DATABASE_NAME -E UTF8 -T template_postgis_osm
createuser -SDR www-data
 
# This will create the planet_osm_ways, etc
$OSM2PGSQL_HOME/osm2pgsql --create --latlong --database $DATABASE_NAME --username rupert --slim --prefix planet_osm --cache 2048 $SOURCE_DATA
 
pg_dump --host 127.0.0.1 --port 5432 --username rupert --format custom --file "$DUMP_DIR/planet_osm_ways.backup" --table public.planet_osm_ways $DATABASE_NAME
pg_dump --host 127.0.0.1 --port 5432 --username rupert --format custom --file "$DUMP_DIR/planet_osm_nodes.backup" --table public.planet_osm_nodes $DATABASE_NAME
pg_dump --host 127.0.0.1 --port 5432 --username rupert --format custom --file "$DUMP_DIR/planet_osm_rels.backup" --table public.planet_osm_rels $DATABASE_NAME
 
# This will create the place table
$OSM2PGSQL_HOME/osm2pgsql --latlong -O gazetteer --database $DATABASE_NAME --username rupert --slim --prefix planet_osm --cache 2048 $SOURCE_DATA
 
pg_restore --host 127.0.0.1 --port 5432 --username rupert --dbname $DATABASE_NAME "$DUMP_DIR/planet_osm_ways.backup"
pg_restore --host 127.0.0.1 --port 5432 --username rupert --dbname $DATABASE_NAME "$DUMP_DIR/planet_osm_nodes.backup"
pg_restore --host 127.0.0.1 --port 5432 --username rupert --dbname $DATABASE_NAME "$DUMP_DIR/planet_osm_rels.backup"
 
rm -Rf $DUMP_DIR/*.backup
 
psql -d $DATABASE_NAME -q -f import_country_osm_grid.sql
psql -d $DATABASE_NAME -q -f import_worldboundaries.sql
psql -d $DATABASE_NAME -q -f import_country_name.sql
psql -d $DATABASE_NAME -q -f import_gb_postcode.sql
psql -d $DATABASE_NAME -q -f import_gb_postcodearea.sql
psql -d $DATABASE_NAME -q -f import_us_state.sql
psql -d $DATABASE_NAME -q -f import_us_statecounty.sql
 
psql -d $DATABASE_NAME -f gazetteer-functions.sql
 
psql -d $DATABASE_NAME -f gazetteer-tables.sql
 
psql -d $DATABASE_NAME -f gazetteer-functions.sql
 
psql -d $DATABASE_NAME -f gazetteer-loaddata.sql
 
#Indexing
psql -d $DATABASE_NAME -f gazetteer-index.sql

Save this as run.sh in /Users/rupert/projects/gis/osm2pgsql/gazetteer

Where do you run this?

% cd /Users/rupert/projects/gis/osm2pgsql/gazetteer
% sh run.sh

6. Test
If you are successful, you should have a “placex” table. Now that we have a postgis database running, you can now run spatial statements thru pgadmin. See the guts of reverse.php

SELECT * 
FROM placex
WHERE ST_DWithin( ST_SetSRID(ST_Point(145.234377, -37.856320),4326), geometry, 0.0001)
AND ST_GeometryType(geometry) NOT IN ('ST_Polygon', 'ST_MultiPolygon')

This one took only 21 ms.

7. Website

Make sure www-data have permissions to the tables. Rememeber to replace gazetteer_vic with your DATABASE_NAME.

for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" gazetteer_vic` ; do psql -c "alter table $tbl owner to \"www-data\"" gazetteer_vic; done

Assuming you have PHP and PEAR DB installed. Then update the data connection settings found in http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/gazetteer/website/.htlib/settings.php

Run the same query but using reverse.php.

http://127.0.0.1/nominatim/reverse.php?format=xml&lat=-37.856320&lon=145.234377&zoom=18&addressdetails=1

reverse.png

Categories: postgis, postgres Tags: , ,

homebrew + php

November 14th, 2011 rupert Comments off

Update
This is now been depracated and used as reference only. I opted to install php via source here

1. Cleanup existing PHP
So by default, OSX Leopard/Snow Leopard?, comes with apache2 and php installed.

mv /usr/local/include/php /usr/local/include/php.old
mv /usr/local/lib/php /usr/local/lib/php.old

2. Install PHP

http://notfornoone.com/2010/07/install-php53-homebrew-snow-leopard/

~/Desktop% brew install php --with-apache --with-mysql --with-pgsql
==> Installing php dependency: jpeg
==> Installing php dependency: mcrypt
==> Installing php dependency: gettext
==> Installing php
....
==> cp ./php.ini-production /usr/local/Cellar/php/5.3.8/etc/php.ini
==> chmod 644 /usr/local/Cellar/php/5.3.8/lib/php/.lock
==> Caveats
   To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/Cellar/php/5.3.8/libexec/apache2/libphp5.so
 
    The php.ini file can be found in:
      /usr/local/Cellar/php/5.3.8/etc/php.ini
brew install php --with-apache --with-mysql --with-pgsql 452.56s user 272.47s system 126% cpu 9:31.75 total

The most important here is the compiled libphp5.so which we will hook into apache2.

3. Hookup Apache2 to libphp5
Depending on your installation, edit httpd.conf and make sure you have this line

LoadModule php5_module    /usr/local/Cellar/php/5.3.8/libexec/apache2/libphp5.so

4. Test

% php -m #List all php modules
mysql
mysqli
pdo_mysql
pdo_pgsql
pgsql
/usr/local/bin% l php #brew makes the symlinks
lrwxr-xr-x  1 rupert  admin    27B 14 Nov 14:42 php@ -> ../Cellar/php/5.3.8/bin/php

Well if you have a wordpress site, you can test if the whole thing works.

5. Restart Apache

sudo /Library/StartupItems/Apache2/Apache2 restart

UPDATE: Dec 19, 2011
Maintaining php installations via homebrew is such a pain. I reverted back via source.
1. Download php from source
2. Configure

./configure --prefix=/usr/local/php5.3.8 \
  --mandir=/usr/share/man \
  --infodir=/usr/share/info \
  --sysconfdir=/etc \
  --with-config-file-path=/etc \
  --with-zlib \
  --with-zlib-dir=/usr \
  --with-openssl \
  --without-iconv \
  --enable-exif \
  --enable-ftp \
  --enable-mbstring \
  --enable-mbregex \
  --enable-sockets \
  --with-mysql=/usr/local/mysql \
  --with-pdo-mysql=/usr/local/mysql \
  --with-mysqli=/usr/local/mysql/bin/mysql_config \
  --with-apxs2=/usr/local/apache2/bin/apxs

3. Make and Make Install

~/Desktop/php-5.3.8% sudo make install
Password:
Installing PHP SAPI module:       apache2handler
/usr/local/apache2.2.14/build/instdso.sh SH_LIBTOOL='/usr/local/apache2.2.14/build/libtool' libs/libphp5.so /usr/local/apache2.2.14/modules
/usr/local/apache2.2.14/build/libtool --mode=install cp libs/libphp5.so /usr/local/apache2.2.14/modules/
cp libs/libphp5.so /usr/local/apache2.2.14/modules/libphp5.so
Warning!  dlname not found in /usr/local/apache2.2.14/modules/libphp5.so.
Assuming installing a .so rather than a libtool archive.
chmod 755 /usr/local/apache2.2.14/modules/libphp5.so
[activating module `php5' in /usr/local/apache2.2.14/conf/httpd.conf]
Installing PHP CLI binary:        /usr/local/php5.3.8/bin/
Installing PHP CLI man page:      /usr/share/man/man1/
Installing build environment:     /usr/local/php5.3.8/lib/php/build/
Installing header files:          /usr/local/php5.3.8/include/php/
Installing helper programs:       /usr/local/php5.3.8/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/share/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php5.3.8/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util: upgrade to a newer version (1.2.1 is not newer than 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/local/php5.3.8/lib/php to your php.ini include_path
/Users/rupert/Desktop/php-5.3.8/build/shtool install -c ext/phar/phar.phar /usr/local/php5.3.8/bin
ln -s -f /usr/local/php5.3.8/bin/phar.phar /usr/local/php5.3.8/bin/phar
Installing PDO headers:          /usr/local/php5.3.8/include/php/ext/pdo/
sudo make install  6.84s user 11.50s system 80% cpu 22.843 total
Categories: Uncategorized Tags: ,

homebrew + mysql = installed but access denied for root

November 14th, 2011 rupert Comments off

1. Cleanup
I have an existing mysql @ /usr/local/mysql, so we remove that.

% sudo rm -rf mysql-5.1.43-osx10.6-x86_64

Note: I suggest you backup your mysql data by doing mysqldump prior to removing the old mysql.

2. Install mysql

#brew install mysql
Set up databases to run AS YOUR USER ACCOUNT with:
    unset TMPDIR
    mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
 
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysqld_install_db:
    mysql_install_db --help
 
and view the MySQL documentation:
  * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
  * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
 
To run as, for instance, user "mysql", you may need to `sudo`:
    sudo mysql_install_db ...options...
 
Start mysqld manually with:
    mysql.server start
 
    Note: if this fails, you probably forgot to run the first two steps up above
 
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
 
To connect:
    mysql -uroot
 
To launch on startup:
* if this is your first install:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
 
* if this is an upgrade and you already have the com.mysql.mysqld.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
    cp /usr/local/Cellar/mysql/5.5.15/com.mysql.mysqld.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
 
You may also need to edit the plist to use the correct "UserName".
 
Warning: m4 macros were installed to "share/aclocal".
Homebrew does not append "/usr/local/share/aclocal"
to "/usr/share/aclocal/dirlist". If an autoconf script you use
requires these m4 macros, you'll need to add this path manually.
==> Summary
/usr/local/Cellar/mysql/5.5.15: 6277 files, 217M, built in 4.9 minutes
brew install mysql  498.39s user 83.40s system 135% cpu 7:08.37 total
~/Desktop% unset TMPDIR
~/Desktop% echo $TMPDIR
 
~/Desktop% mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
 
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root password 'new-password'
/usr/local/Cellar/mysql/5.5.15/bin/mysqladmin -u root -h rupert-imac password 'new-password'
 
Alternatively you can run:
/usr/local/Cellar/mysql/5.5.15/bin/mysql_secure_installation
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon with:
cd /usr/local/Cellar/mysql/5.5.15 ; /usr/local/Cellar/mysql/5.5.15/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/Cellar/mysql/5.5.15/mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the /usr/local/Cellar/mysql/5.5.15/scripts/mysqlbug script!
~/Desktop% which mysql.server
/usr/local/bin/mysql.server
~/Desktop% ls -la `which mysql.server`
lrwxr-xr-x  1 rupert  admin  39 30 Dec 11:20 /usr/local/bin/mysql.server@ -> ../Cellar/mysql/5.5.15/bin/mysql.server
~/Desktop% mysql.server start
Starting MySQL
.. SUCCESS!

3. That’s it? No.

At the time of writing this, mysql is at 5.5 and was installed successfully by homebrew. However, I cannot login using the root account. Have a read of this stackoverflow: brew install mysql on mac os.

To fix this, stop mysql

launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

and start mysql by skipping the grant tables.

mysqld_safe --skip-grant-tables

Depending if you have a record in mysql.user (select * from mysql.user), then you can either create or update the user.

create:

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'whatever' WITH GRANT OPTION;
FLUSH PRIVILEGES;

update:

UPDATE mysql.user SET Password = PASSWORD('NewPassword') WHERE User='root';
FLUSH PRIVILEGES;

4. Cleanup paths
This is just removing the pgsql and mysql from the current path

export PATH=$PATH:$ORACLE_HOME:$MYSQL_HOME/bin:$CLANG_HOME:$ANDROID_HOME/tools:$APACHE2_HOME/bin:$MAGICK_HOME/bin:$SPHINX_HOME/bin:$PGSQL_HOME/bin
Categories: homebrew, mysql, osx Tags: , ,