Thursday, June 18, 2015

Command line start MySQL.
sudo /usr/local/mysql/support-files/mysql.server start
To find the MySQL version from the terminal, type at the prompt:
/usr/local/mysql/bin/mysql -v
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:
cd ; nano .bash_profile
export PATH="/usr/local/mysql/bin:$PATH"
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.
source ~/.bash_profile
mysql -v
You will get the version number again, just type “q” to exit.

Set the MySQL root password

Note that this is not the same as the root or admin password of OSX – this is a unique password for the mysql root user, use one and remember/jot down somewhere what it is.
/usr/local/mysql/bin/mysqladmin -u root password 'yourpasswordhere'
Use the single ‘quotes’ surrounding the password

Fix the 2002 MySQL Socket error

Fix the looming 2002 socket error – which is linking where MySQL places the socket and where OSX thinks it should be, MySQL puts it in /tmp and OSX looks for it in /var/mysql the socket is a type of file that allows mysql client/server communication.
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

AutoStarting MySQL on Reboot

There was a solution recently posted on how to autostart MySQL on reboot on Yosemite, if you follow this it will work:
sudo nano /Library/LaunchDaemons/com.mysql.mysql.plist
And paste in:


  
    KeepAlive
    
    Label
    com.mysql.mysqld
    ProgramArguments
    
      /usr/local/mysql/bin/mysqld_safe
      --user=mysql
            
  
Save it and then:
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
Then it will load on a restart.

No comments: