Resolve macport installed mysql from defaulted mysql from mac osx

November 14, 2009 § Leave a comment

Using mac osx MacPorts to install latest version of MySQL are challenging as the macports version is buggy on MySQL5.0 or later. You may have a defaulted installed MySQL on your mac osx on the path /usr/local/mysql/bin. Macports install MySQL5 to another path /opt/local/bin.

Determine mysql version:
mysql -v

Go to the path where the MySQL is installed to verify the mysql version.

If you never create a password for user root, then you skip password by leaving the password blank. You would have to use sudo in order to view all the database within mysql. Defaulted installed mysql is located at /usr/local/mysql/bin.

Run mysql:
sudo /usr/local/mysql/bin/mysql

Or Run mysql:
/usr/local/mysql/bin/mysql -u root -p

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.84 MySQL Community Server (GPL)

Quit mysql:
mysql> exit;

Run mysql from macports installed ports:
/opt/local/bin/mysql5 -u root -p

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)

To view the database from Defaulted MySQL:

cd /usr/local/mysql
sudo chown -R mysql data/
sudo echo
sudo ./bin/mysqld_safe &
/usr/local/mysql/bin/mysql test

If you do not want to have to type /usr/local/mysql/bin in front of every single mysql-related command, then you have to add the /usr/local/mysql/bin directory to your PATH environment variable in your shell’s login script.

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bashrc

Create a password for user root:
/usr/local/mysql/bin/mysqladmin -u root password new_password_here

To view the database from macports installed MySQL:
cd /opt/local/var/db/mysql5
ls -l

Macports version of mysqld.sock should be located here
/opt/local/var/run/mysql5

To resolve this mysqld.sock error:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)

Create a symbolic link of mysql.sock from any possible source:
ls /tmp/mysql.sock
sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
ls -a /opt/local/var/run/mysql5/mysqld.sock
mysql -u root -p

Note: skip the password as blank if you haven’t created a password for user root

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Resolve macport installed mysql from defaulted mysql from mac osx at Web Builders.

meta

%d bloggers like this: