July 02, 2015

MySQL in Yosemite



This is the second article on marvellous Yosemite. This time we're installing and configuring MySQL.

Download MySQL and run the pkg installer, there's an issue the MySQL LaunchDeamon script, so if the installation fails it's ok the files are there, but the MySQL deamon could not be added. To add the MySQL deamon to launchctl the LaunceDeamon file needs to be created.

# echo "<!--?xml version="1.0" encoding="UTF-8"?-->
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true />
    <key>Label</key>
    <string>com.mysql.mysqld</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/mysql/bin/mysqld_safe</string>
      <string>--user=mysql</string>
    </array>        
  </dict>
</plist>" | sudo tee /Library/LaunchDaemons/com.mysql.mysql.plist 

Once you have your file created, you'll need to set the file premissions, like we did for apache, and add the file to the launch deamon.

# sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist 
# sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist 
# sudo launchctl -w /Library/LaunchDaemons/com.mysql.mysql.plist 

There are some socket logging issues that needs to be fixed, apparently a file is missing the /var folder. 

# sudo mkdir /var/mysql
# sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Next, you'll need to add the MySQL to your bash environment

# echo 'export PATH="/usr/local/mysql/bin:$PATH"' > ~/.bash_profile

Or you could add it to your bashrc file using >> ~/.bashrc its up to you. Then source the MySQL environment into your environment. This environment should be set at every log on via your .bash_profile file. To verify the environment type:

# mysql -v

You quit the MySQL shell using \q (escaped q). To setup the MTSQL root users password type:

# mysqladmin -u root password 'thepasswordyoulike'

You should now be able to run MySQL from your command line.

No comments: