Posts Tagged ‘osx’

Fancy Mac (OS-x) Prompt

The Problem

Boring promt

The Fix

– Open a Terminal window.

– Edit your .profile or create a file like so vi ~/.profile

Add the following to the file:

alias vi=’vim’
3
4 alias ol=’ssh root@192.168.10.206′
5 #alias cade=’ssh 74.86.232.5′
6 alias cade=’ssh 74.63.12.158′
7 alias oce=’ssh root@74.208.45.99′
8
9 # colors
10 export CLICOLOR=1
11 export TERM=xterm-color
12 export LSCOLORS=gxgxcxdxbxegedabagacad  # cyan directories
13 export PS1=’\[33[01;32m\]\u@\h\[33[00m\]:\[33[01;36m\]\w\[33[00m\]\$ ‘

# Starts the extended vi when using vi
alias vi=’vim’
# Nice listing using ll
alias ll=’ls -Alhp’

export CLICOLOR=1
export TERM=xterm-color
# Information about the colors at the bottom of the article
export LSCOLORS=gxgxcxdxbxegedabagacad  # cyan directories
export PS1=’\[33[01;32m\]\u@\h\[33[00m\]:\[33[01;36m\]\w\[33[00m\]\$ ‘

This will make sure that you prompt will have ansi colors and look something like this:
freddy@svn:~/Documents$ ll drwxr-xr-x  17 freddy  staff   578B Feb 10  2008 cadechristian.com_project/ -rw-r--r--@  1 freddy  staff   112K Mar  1  2008 server.docx drwxrwxrwx   4 freddy  staff   136B Jan 28  2008 server_backup/ -rw-r--r--@  1 freddy  staff   559K Mar  3  2008 sunJVM-on-intel-multicoreservers.pdf -rw-r--r--@  1 freddy  staff   556K Mar  1  2008 tomcat_performance_tuning_20071015.ppt freddy@svn:~/Documents$ 

LSCOLOR information

These are the available ANSI colors:

a     black
b     red
c     green
d     brown
e     blue
f     magenta
g     cyan
h     light grey
A     bold black, usually shows up as dark grey
B     bold red
C     bold green
D     bold brown, usually shows up as yellow
E     bold blue
F     bold magenta
G     bold cyan
H     bold light grey; looks like bright white
x     default foreground or background 

Note that the above are standard ANSI colors. The actual display may differ depending on the color capabilities of the terminal in use. The order of the attributes in the LSCOLORS variable is as follows:

  1. directory
  2. symbolic link
  3. socket
  4. pipe
  5. executable
  6. block special
  7. character special
  8. executable with setuid bit set
  9. executable with setgid bit set
  10. directory writable to others, with sticky bit
  11. directory writable to others, without sticky bit

They are set in pairs, foreground (f) then background (b), i.e. fbfbfbfbfbfbfbfbfbfbfb for all 11 settings. The default is exfxcxdxbxegedabagacad, i.e. blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc.

Mysql5 in OSX

Install mac ports

Install Mysql:
freddy@new-host-2:~$ port list | grep mysql5
mysql5 @5.0.67 databases/mysql5
mysql5-devel @5.1.28-rc databases/mysql5-devel
freddy@new-host-2:~$ port install mysql5

  • First run this command in your terminal to install the MySQL 5 package:

    sudo port install mysql5 +server
  • Second load the MySQL server by running the following command: (Note: Mac OS X Tiger and above use launchd for starting programs, and this command is worth getting familiar with. In this case the startup configuration file was created for us when we installed MySQL 5.)

    sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
  • Third figure out the path for your server socket. It should be /opt/local/var/run/mysql5/mysqld.sock but verify this by running this command:

    mysql_config5 --socket
    /opt/local/var/run/mysql5/mysqld.sock
  • Fourth you want to create a shortcut to the MySQL socket so that PHP, Ruby on Rails, Python, and your other languages can access it. These commands should make MySQL work for PHP and Ruby on Rails:

    sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
    sudo mkdir /var/mysql
    sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /var/mysql/mysql.sock
  • Fifth you will need to shut down the MySQL server for now. Run this command:

    sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist
  • Sixth you need to setup the root user and the default MySQL database. Sometimes called the grant tables. To do this run this command:

    sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
  • And last you’ll need to start up the MySQL server and then login and change the root password.

    sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
    mysql5 -u root
    UPDATE mysql.user SET Password = PASSWORD('password') WHERE User = 'root';
    FLUSH PRIVILEGES;
    quit
  • Now you should be able to login using your new password.

    mysql5 -u root -p

That’s it you’re all setup with MySQL on Mac OS X.

MySQL on Leopard for rails

SQLite is a great little tool and very easy to use and setup… gem install sqlite3-ruby and you are done!! But now I’m creating a rails application that needs foreign keys and that’s something that SQLite does not do. So MySQL it is…(I’m a MySQL guy if you haven’t figured)
My choice to install MySQL on the macbook was using macports… I’ll assume that macports is installed correctly for the next exercises…  (port version should give you the version number)
Installing MySQL 5.0 with port:
sudo port install mysql5 +server
When the installation is done you have to create the run directory
sudo mkdir /opt/local/var/run
sudo mkdir /opt/local/var/run/mysql5
cd /opt/local/var/run
sudo chown _mysql mysql5
ls -al
total 0
drwxr-xr-x  4 _mysql  admin   136B Mar 12 10:37 mysql5/
setup the config file for MySql. (use the template so you can see where Mysql puts stuff)
sudo /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf
Testing if MySQL Starts…
sudo /opt/local/lib/mysql5/bin/mysqld_safe5
(you will need crtl-Z and then type bg. This will put the MySQL process in the background. type jobs to see the process)
now connect to mysql with the client
mysql5 -uroot
If you want to stop MySQL you have to kill the process. ps -ax | grep mysqld… there should be one mysqld and one mysqld_sfae5 process get BOTH pids and run kill pid pid.
ps -ax | grep mysqld 70170   ??  S      0:00.01 /bin/sh /opt/local/lib/mysql5/bin/mysqld_safe –datadir=/opt/local/var/db/mysql5 –pid-file=/opt/local/var/db/mysql5/new-host-2.home.pid
70195   ??  S      0:01.22 /opt/local/libexec/mysqld –basedir=/opt/local –datadir=/opt/local/var/db/mysql5 –user=mysql –pid-file=/opt/local/var/db/mysql5/new-host-2.home.pid –port=3306 –socket=/opt/local/var/run/mysql5/mysqld.sock kill  70170 70195
If you only kill one the server will auto restart!!
Running MySQL using MySQL launchctl
This is where I need more help BUT this is what I did and it works:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist  
PS(make sure you kill mysqld_safe5 before doing this…)
Now the part I don’t udnerstand… the server just started but I don’t know how to CONTROL the server like stop, start and restart???
sudo launchctl stop org.macports.mysql5

This did “restart” MySQL but using start/restart did nothing. Looks like when you stop MySQL it aut restart from lunched. 

Password for MySQL root user?
mysqladmin5 -u password ‘secret-password’
connecting with password
mysql5 -uroot -p