18.3. PostgreSQL

 < Day Day Up > 

18.2. MySQL

To get the source distribution of MySQL, download the latest tarball from http://dev.mysql.com/downloads/.

At the time of this writing, we weren't able to get the most recent production version (4.1.x) of MySQL to compile out of the box on Mac OS X Tiger. We were able to get an earlier version (4.0.24) working, but we had to use the GCC 3.3 compiler. You can use the command gcc_select 3.3 to specify the GCC 3.3 compiler or use this command under sh or bash to tell configure to use GCC 3.3:

     CC=gcc-3.3 CXX=g++-3.3 ./configure \       --prefix=/usr/local/mysql


18.2.1. Compiling MySQL

To compile MySQL from source :

  1. Extract the tarball:

         $ cd ~/src     $ tar xvfz ~/Desktop/mysql-4.0.24.tar.gz

  2. Change to the top-level directory that tar created and run the configure script. We suggest specifying a prefix of /usr/local/mysql so it stays out the way of any other binaries you have in /usr/local.

         $ cd mysql-4.0.24/     $ ./configure --prefix=/usr/local/mysql

  3. Next, type make to compile MySQL. Go get a few cups of coffee (compiling could take 20 minutes or more).

18.2.2. Installing MySQL

If the compilation succeeded, you're ready to install MySQL. If it didn't succeed, you should first search the MySQL mailing list archives (http://lists.mysql.com) to see if anyone has reported the same problem you experienced, and whether a fix is available (otherwise, you should submit a bug report). If you're having a lot of trouble here, you may want to install one of the binary packages. If everything went OK, you can now install MySQL:

  1. Run make install as root:

         $ sudo make install

  2. Install the default configuration file and databases:

         $ sudo cp support-files/my-medium.cnf /etc/my.cnf     $ cd /usr/local/mysql     $ sudo ./bin/mysql_install_db --user=mysql

  3. Set permissions on the MySQL directories:

         $ sudo chown -R root  /usr/local/mysql     $ sudo chown -R mysql /usr/local/mysql/var     $ sudo chgrp -R mysql /usr/local/mysql

  4. Now you're ready to install a startup script for MySQL. See "Startup Items" in Chapter 4 for a sample MySQL startup script. After you've created the startup script, start MySQL:

         $ sudo SystemStarter start MySQL

18.2.3. Configuring MySQL

Next, you need to configure MySQL. At a minimum, set the root user's password and create a user and a working database for that user. Before using MySQL, add the following line to your .bash_profile and start a new Terminal window to pick up the settings:

     export PATH=$PATH:/usr/local/mysql  /bin 

To set the root password and create a new user:

  1. Use mysqladmin to set a password for the root user (qualified as root@localhost and just plain old root). When you enter the second line, there will be a root password in place, so you need to use -p, and you'll be prompted for the password you created on the first line:

         $ mysqladmin -u root password ' password '      $ mysqladmin -u root -p -h localhost password ' password '      Enter password: ******** 

  2. Create a database for your user (you'll be prompted for the mysql root user's password):

         $ mysqladmin  -u root -p create dbname     Enter password: ********

  3. Log into the mysql shell as root, and grant full control over that database to your user, qualified both as user@localhost as well as the username alone (the -> prompt indicates that you pressed return without completing the command, and the mysql shell is waiting for more input):

         $ mysql -u root -p      Enter password: ********      Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 12 to server version: 4.0.16-log     Type 'help;' or '\h' for help. Type '\c' to clear the buffer.     mysql> GRANT ALL PRIVILEGES ON  dbname .* TO  username @localhost          -> IDENTIFIED BY ' password ';      Query OK, 0 rows affected (0.08 sec)     mysql> GRANT ALL PRIVILEGES ON  dbname .* TO  username          -> IDENTIFIED BY ' password ';      Query OK, 0 rows affected (0.00 sec) mysql> quit  Bye 

18.2.4. Using MySQL

You should be able to log in to MySQL as the user defined in the previous section, and do whatever you want within your database:

     $ mysql -u  username  -p  dbname      Enter password: ********      Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 16 to server version: 4.0.16-log     Type 'help;' or '\h' for help. Type '\c' to clear the buffer.     mysql> CREATE TABLE foo (bar CHAR(10));      Query OK, 0 rows affected (0.06 sec)     mysql> INSERT INTO foo VALUES('Hello');      Query OK, 1 row affected (0.00 sec)     mysql> INSERT INTO foo VALUES('World');      Query OK, 1 row affected (0.01 sec)     mysql> SELECT * FROM foo;      +-------+     | bar   |     +-------+     | Hello |     | World |     +-------+     2 rows in set (0.00 sec)     mysql> quit      Bye 

     < Day Day Up > 


    Mac OS X Tiger for Unix Geeks
    Mac OS X Tiger for Unix Geeks
    ISBN: 0596009127
    EAN: 2147483647
    Year: 2006
    Pages: 176

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net