• Tidak ada hasil yang ditemukan

Mac OS X Distributions

Dalam dokumen Buku Learning MySQL and MariaDB (Halaman 42-45)

Recent versions of Mac OS X no longer come with MySQL installed, but previous ones did — they stopped shipping it after Oracle took over MySQL. If your computer started with an older version, it may already be installed, but not running. To see if you have MySQL installed on your system, open the Terminal application (located in

Applications/Utilities). Once you have a command prompt, enter the first line shown here

(the results you should see are on lines 2–4):

whereis mysql mysqld mysqld_safe /usr/bin/mysql

/usr/bin/mysqld /usr/bin/mysqld_safe

If you get the results just shown, MySQL is installed on your computer. Check now

whether the MySQL daemon (mysqld) is running. Enter the following from the command line:

ps aux | grep mysql

If it shows that mysqld is running, you don’t need to install it, but skip instead to Post- Installation.

If the daemon is present on your system but not running, enter the following from the command line as root to start it:

/usr/bin/mysqld_safe &

If MySQL is not installed on your Mac system or you want to upgrade your copy of MySQL by installing the latest release, directions are included in the remainder of this section. If MySQL isn’t already installed on your system, you may need to create a system user named mysql before installing MySQL. Oracle’s MySQL package automatically creates a user called _mysql.

Binary file packages (DMG files) are available for installing MySQL. For Mac servers that do not have a GUI or a desktop manager, or for when you want to install it remotely, there are TAR files for installing MySQL.[3] Whether you will be downloading a DMG file or a TAR file, be sure to download the package related to the type of processor on your server (e.g., 32-bit or 64-bit), and for the minimum version of the server’s operating system (e.g., Mac OS X, version 10.6 or higher).

If an older version of MySQL is already installed on your server, you will need to shut down the MySQL service before installing and running the newer version or replacing it with MariaDB. You can do this with the MySQL Manager Application, which is a GUI application that was probably installed when the operating system was first installed along with MySQL. It’s typically installed on recent versions of Mac OS X by default. If your server doesn’t have the MySQL Manager Application, you can enter the following from the command line to shut down the MySQL service:

/usr/sbin/mysqladmin -u root -p shutdown

If you’ve never used MySQL and didn’t set the password, it’s probably blank. When you’re prompted for it after entering the preceding command, just press the Enter key.

To install the MySQL package file, from the Finder desktop manager, double-click on the disk image file (the DMG file) that you downloaded. This will reveal the disk image file’s contents. Look for the PKG files; there will be two. Double-click on the one named

mysql-version.pkg (e.g., mysql-5.5.29-osx10.6-x86.pkg). This will begin the installation program. The installer will take you through the installation steps from there. The default settings are recommended for most users and developers.

To have MySQL started at boot time, add a startup item. Within the disk image file that

you downloaded, you should see an icon labeled MySQLStartupItem.pkg. Just double- click it, and it will create a startup item for MySQL. You should also install the MySQL preferences pane so that you can start and stop MySQL easily from Systems Preferences in the Mac system, as well as set it to start automatically at start up time. To do this, click on the icon labeled MySQL.prefPane. If you have problems using the installer, read the ReadMe.txt file included in the DMG image file.

There is not yet an official installer for MariaDB on a Mac machine. However, you can use homebrew to download and install the needed packages, including required libraries.

The homebrew utility works much like yum does on Linux systems, but is made for Mac OS X. After you install homebrew, you can run the following from the command line to install MariaDB:

brew install mariadb

To install MySQL with the TAR package instead of the DMG package, download the TAR file from Oracle’s site and move it to the /usr/local directory, then change to that directory.

Next, untar and unzip the installation program like so:

cd /usr/local

tar xvfz mysql-version.tar.gz

Change the name of the installation package in the example to the actual name. From here, create a symbolic link for the installation directory, and then run the configuration

program. Here is an example of how you might do this:

ln -s /usr/local/mysql-version /usr/local/mysql cd /usr/local/mysql

./configure --prefix=/usr/local/mysql \

--with-unix-socket-path=/usr/local/mysql/mysql_socket \ --with-mysqld-user=mysql

The first line creates the symbolic link to give MySQL a universal location regardless of future versions; change version to the actual version number. By making a symbolic link to a generic directory of /usr/local/mysql, you’ll always know where to find MySQL when you need it. You could also just rename the directory with the version name to just mysql.

But then you can’t test new versions and keep old versions when upgrading.

With the second line, you enter the directory where the installation files are now located.

The third line runs the configuration program to install MySQL. I’ve included a few options that I think will be useful for solving some problems in advance. Depending on your needs, you might provide more options than these few. However, for most beginners, these should be enough.

Next, you should set who owns the files and directories created, and which group has rights to them. Set both the user and group to mysql, which should have been created by the installation program. For some systems, you may have to enable permissions for the hard drive or volume first. To do that, use the vsdbutil utility. If you want to check whether permissions are enabled on the volume first, use the -c option; to just enable it, use -a option for vsdbutil. You should also make a symbolic link from the /usr/bin directory to the mysql and mysqladmin clients:

vsdbutil -a /Volumes/Macintosh\ HD/

sudo chown -R _mysql /usr/local/mysql/.

alias mysql=/usr/local/mysql/bin/mysql

alias mysqladmin=/usr/local/mysql/bin/mysqladmin

The first line of this example enables the main drive of the Mac machine. The name of the drive on which you locate MySQL may be different on your server. The second line

changes the owner to the user mysql. The last two lines create aliases for the two key MySQL clients mentioned earlier so that you can run them from anywhere on your system.

At this point, you should be able to start the daemon and log into MySQL or MariaDB. If you installed the preference pane for MySQL with the installer, you can go to the Systems Preference of the operating system and start it there instead:

sudo /usr/bin/mysqld_safe &

mysql -u root -p

Depending on the release of MySQL, the file path for a dmg installation may be different from what is shown in the first line here. An ampersand (&) sends the process to the background. The second line will start the mysql client and let you log in as root, the MySQL user who is in control of the whole server — MySQL users are different from operating system users, so the root user is also different even though the name is the same.

The command will prompt you for a password, which will probably be blank. So you can just press Enter for the password and you’ll be in.

Success here simply shows that you can connect to the MySQL or MariaDB server and that you have correctly added the symbolic links for the mysql client. There’s more to do before you start trying MySQL. So type exit and press Enter to exit the mysql client.

Now that MySQL or MariaDB is installed and running, you need to make some post- installation adjustments, as explained in Post-Installation. Skip ahead to that section.

Dalam dokumen Buku Learning MySQL and MariaDB (Halaman 42-45)