Mac OS X: mySQL install

    Mac OS X: mySQL install

    .

    31 May 2001 – This page describes the installation, configuration, and use of mySQL, a robust, free, cross-platform, open source relational database. Rather than describing what you’re doing, I’ll show you exactly what to do. You’ll do the work of acquiring and installing software from within the Terminal application, using a web browser only for the testing steps.

    I assure you that the UNIX commands I’ll direct you to invoke have been taken directly from a Terminal window – these are the commands I just used to do a clean install – rather than having been composed after the fact. This is *exactly* what worked for me. I’ve taken pains to choose forms of the commands which should make sense to you even if you’re new to UNIX.

    Prepare your environment

    Using your favorite text editor (pico, vi, or emacs on the command-line side or SimpleText or BBEdit on the graphic user interface side) edit (or create and edit) a file named .tcshrc in your home directory. Edit this file and ncorporate the following:

    # mySQL relational database

    setenv MYSQL_HOME /usr/local/mysql

    setenv PATH ${PATH}:${MYSQL_HOME}/bin

    setenv MANPATH ${PATH}:${MYSQL_HOME}/man

    Save the file, return to the Terminal, and set your environment with the settings we just created.

    % chmod 775 ~/.tcshrc

    % source ~/.tcshrc

    Create the ‘mysql’ user

    The correct way of installing mySQL is to have it owned by a user (albeit a virtual one, rather than you, who are a more physical one :-). Having software being owned by a user makes it easy to administer privileges: if we let the root user own the software then it could do anything it wanted (if something went wrong or security was compromised). Having you own it means that you can’t tell what you own and what it owns. If you see anything owned by user mysql then you’ll have a good clue as to what it is.

    Using the NetInfo Manager to create a new Mac OS X user has been covered extensively elsewhere on the net, and I don’t really want to go into it here. I’m sorry, but it’s late at night, and I have to read a few stories to my son.

    Create a home for the mySQL database

    Where will we install the software? By convention we put it into /usr/local/mysql.

    % sudo mkdir /usr/local/mysql

    % sudo chown mysql /usr/local/mysql

    Get the software

    We create a local workspace, acquire the software, and decompress it.

    % mkdir ~/install ; cd ~/install

    % wget http://www.mysql.com/Downloads/MySQL-3.23/mysql-3.23.38.tar.gz

    % gnutar zxf mysql-3.23.38.tar.gz

    % cd mysql-3.23.38/

    Become the mysql user

    Because we want all the files and directories of the installed product to belong to the mysql, we become that user. One way is to su mysql, but I prefer the following:

    % sudo -u mysql tcsh

    % set prompt=”mysql % ”

    mysql %

    What am I doing? I’m running the tcsh shell as the mysql user and setting the prompt to remind me of my new identity.

    Build the software

    I’ve elided the output of these commands because there’s a lot of it. The main make step takes a few hours, compiling many files. In the last step I preserve the automatic startup “run commands” file from the distribution, which we’ll be deleting when we’re done.

    mysql % ./configure –prefix=/usr/local/mysql

    mysql % make

    mysql % make install

    mysql % scripts/mysql_install_db

    mysql % mkdir /usr/local/mysql/automatic-startup/

    myqsl % mv support-files/mysql.server /usr/local/mysql/automatic-startup/

    mysql % ^D

    %

    The last step? I type a Control-D to end the shell. (Control-D is the UNIX EOD – End of Data – keystroke, and is useful in lots of places. Keep your eyes open… 🙂

    Start the daemon

    A daemon, pronounced “demon”, is a bit of software which runs in the background (without a command line or graphic user interface). You have many of them running on the standard Mac OS X install. This one’ll do our database bidding.

    % cd /usr/local/mysql

    % sudo /usr/local/mysql/bin/safe_mysqld &

    I thought I could run the daemon as mysql, but it seemed only to be happy to be run as root. I may have missed something in my quick analysis. If you know better, either way, please let me know.

    First-time administration

    Now that things are running, we have to become the database administrator (DBA) for a moment and provide passwords to mysql. Even if you’re running this locally, only for development purposes, take a second and give it a non-trivial password.

    mySQL is installed without a password. For this example I’m changing that to ‘opensesame”. In the first step, when asked for a password, I just hit the Return key, signifying no password. This assigns the password ‘opensesame’ to a system without a password. In the second step, when asked for a password, I type the new password, ‘opensesame’.

    % mysqladmin -u root -p password opensesame

    Enter password: [return]

    % mysqladmin -u root -h localhost -p password opensesame

    Enter password: opensesame

    Testing the installed mySQL

    % mysql -u root -h localhost -p

    Enter password:

    Welcome to the MySQL monitor.

    Commands end with ; or g.

    Your MySQL connection id is 19 to server version: 3.23.38

    Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer

    mysql> select host, user from mysql.user ;

    +———–+——+

    | host

    | user |

    +———–+——+

    | localhost |

    |

    | localhost | root |

    +———–+——+

    2 rows in set (0.42 sec)

    mysql> ^D

    Bye

    %

    %

    % mysqladmin -u root -p status

    Enter password: opensesame

    Uptime: 366

    Threads: 1

    Questions: 1

    Slow queries: 0

    Opens: 6

    Flush tables: 1

    Open tables: 0 Queries per second avg: 0.003

    %

    So now we have a working mySQL. I haven’t explored having it automatically start up, and it seems that one must do the following to shut down the server:

    % mysqladmin -u root -p -v shutdown

    Enter password: opensesame

    Shutdown signal sent to server;

    Waiting for pid file to disappear

    %

    although I’ve heard that the only way to actually stop it is to kill it, as follows:

    % ps -auxc | grep mysqld

    root

    5093

    0.0

    0.3

    11444

    1404

    p4

    S+

    0:00.18 mysqld

    % sudo kill -9 5093

    %

    I’ll do a bit more digging. I want things to be cleaner.

    I haven’t really explored using mySQL from the JavaServer Pages I’m running under

    and . I’ll get on it.

    Clean up after yourself

    Let’s remove the install directory now that we’re done. (I’m not sure we’re really done: there’s the sql-bench tests and perhaps other things, but so it goes. I can always download it again, should the need arise. You have been warned.)

    % cd ~

    % rm -rf ./install

    You might want to – okay, you really ought to – jump up one level, to see how this fits into the

    of developing and deploying web-based applications (and to see what other tools I’ve installed to work with this one).

    This page

    is

    1993-2006 by ,

    via the Creative Commons License. Questions and comments? Send

    to the Geek Times Webmaster. (Domain and web content hosting at .)

    Leave a Reply

    Your email address will not be published.

    Mac OS X: mySQL install

    Mac OS X: mySQL install

    .

    31 May 2001 – This page describes the installation, configuration, and use of mySQL, a robust, free, cross-platform, open source relational database. Rather than describing what you’re doing, I’ll show you exactly what to do. You’ll do the work of acquiring and installing software from within the Terminal application, using a web browser only for the testing steps.

    I assure you that the UNIX commands I’ll direct you to invoke have been taken directly from a Terminal window – these are the commands I just used to do a clean install – rather than having been composed after the fact. This is *exactly* what worked for me. I’ve taken pains to choose forms of the commands which should make sense to you even if you’re new to UNIX.

    Prepare your environment

    Using your favorite text editor (pico, vi, or emacs on the command-line side or SimpleText or BBEdit on the graphic user interface side) edit (or create and edit) a file named .tcshrc in your home directory. Edit this file and ncorporate the following:

    # mySQL relational database

    setenv MYSQL_HOME /usr/local/mysql

    setenv PATH ${PATH}:${MYSQL_HOME}/bin

    setenv MANPATH ${PATH}:${MYSQL_HOME}/man

    Save the file, return to the Terminal, and set your environment with the settings we just created.

    % chmod 775 ~/.tcshrc

    % source ~/.tcshrc

    Create the ‘mysql’ user

    The correct way of installing mySQL is to have it owned by a user (albeit a virtual one, rather than you, who are a more physical one :-). Having software being owned by a user makes it easy to administer privileges: if we let the root user own the software then it could do anything it wanted (if something went wrong or security was compromised). Having you own it means that you can’t tell what you own and what it owns. If you see anything owned by user mysql then you’ll have a good clue as to what it is.

    Using the NetInfo Manager to create a new Mac OS X user has been covered extensively elsewhere on the net, and I don’t really want to go into it here. I’m sorry, but it’s late at night, and I have to read a few stories to my son.

    Create a home for the mySQL database

    Where will we install the software? By convention we put it into /usr/local/mysql.

    % sudo mkdir /usr/local/mysql

    % sudo chown mysql /usr/local/mysql

    Get the software

    We create a local workspace, acquire the software, and decompress it.

    % mkdir ~/install ; cd ~/install

    % wget http://www.mysql.com/Downloads/MySQL-3.23/mysql-3.23.38.tar.gz

    % gnutar zxf mysql-3.23.38.tar.gz

    % cd mysql-3.23.38/

    Become the mysql user

    Because we want all the files and directories of the installed product to belong to the mysql, we become that user. One way is to su mysql, but I prefer the following:

    % sudo -u mysql tcsh

    % set prompt=”mysql % ”

    mysql %

    What am I doing? I’m running the tcsh shell as the mysql user and setting the prompt to remind me of my new identity.

    Build the software

    I’ve elided the output of these commands because there’s a lot of it. The main make step takes a few hours, compiling many files. In the last step I preserve the automatic startup “run commands” file from the distribution, which we’ll be deleting when we’re done.

    mysql % ./configure –prefix=/usr/local/mysql

    mysql % make

    mysql % make install

    mysql % scripts/mysql_install_db

    mysql % mkdir /usr/local/mysql/automatic-startup/

    myqsl % mv support-files/mysql.server /usr/local/mysql/automatic-startup/

    mysql % ^D

    %

    The last step? I type a Control-D to end the shell. (Control-D is the UNIX EOD – End of Data – keystroke, and is useful in lots of places. Keep your eyes open… 🙂

    Start the daemon

    A daemon, pronounced “demon”, is a bit of software which runs in the background (without a command line or graphic user interface). You have many of them running on the standard Mac OS X install. This one’ll do our database bidding.

    % cd /usr/local/mysql

    % sudo /usr/local/mysql/bin/safe_mysqld &

    I thought I could run the daemon as mysql, but it seemed only to be happy to be run as root. I may have missed something in my quick analysis. If you know better, either way, please let me know.

    First-time administration

    Now that things are running, we have to become the database administrator (DBA) for a moment and provide passwords to mysql. Even if you’re running this locally, only for development purposes, take a second and give it a non-trivial password.

    mySQL is installed without a password. For this example I’m changing that to ‘opensesame”. In the first step, when asked for a password, I just hit the Return key, signifying no password. This assigns the password ‘opensesame’ to a system without a password. In the second step, when asked for a password, I type the new password, ‘opensesame’.

    % mysqladmin -u root -p password opensesame

    Enter password: [return]

    % mysqladmin -u root -h localhost -p password opensesame

    Enter password: opensesame

    Testing the installed mySQL

    % mysql -u root -h localhost -p

    Enter password:

    Welcome to the MySQL monitor.

    Commands end with ; or g.

    Your MySQL connection id is 19 to server version: 3.23.38

    Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer

    mysql> select host, user from mysql.user ;

    +———–+——+

    | host

    | user |

    +———–+——+

    | localhost |

    |

    | localhost | root |

    +———–+——+

    2 rows in set (0.42 sec)

    mysql> ^D

    Bye

    %

    %

    % mysqladmin -u root -p status

    Enter password: opensesame

    Uptime: 366

    Threads: 1

    Questions: 1

    Slow queries: 0

    Opens: 6

    Flush tables: 1

    Open tables: 0 Queries per second avg: 0.003

    %

    So now we have a working mySQL. I haven’t explored having it automatically start up, and it seems that one must do the following to shut down the server:

    % mysqladmin -u root -p -v shutdown

    Enter password: opensesame

    Shutdown signal sent to server;

    Waiting for pid file to disappear

    %

    although I’ve heard that the only way to actually stop it is to kill it, as follows:

    % ps -auxc | grep mysqld

    root

    5093

    0.0

    0.3

    11444

    1404

    p4

    S+

    0:00.18 mysqld

    % sudo kill -9 5093

    %

    I’ll do a bit more digging. I want things to be cleaner.

    I haven’t really explored using mySQL from the JavaServer Pages I’m running under

    and . I’ll get on it.

    Clean up after yourself

    Let’s remove the install directory now that we’re done. (I’m not sure we’re really done: there’s the sql-bench tests and perhaps other things, but so it goes. I can always download it again, should the need arise. You have been warned.)

    % cd ~

    % rm -rf ./install

    You might want to – okay, you really ought to – jump up one level, to see how this fits into the

    of developing and deploying web-based applications (and to see what other tools I’ve installed to work with this one).

    This page

    is

    1993-2006 by ,

    via the Creative Commons License. Questions and comments? Send

    to the Geek Times Webmaster. (Domain and web content hosting at .)

    Leave a Reply

    Your email address will not be published.