MySQL Database Server
- Introduction
- Installation Instructions
- Database Re-Initialization
- Update Instructions
- Examples
- FAQ
- Additional Information
- Build Instructions
Introduction
The MySQL database server is very popular for building web applications, it is often used in combination with the PHP language.
Since version 4.0.11, I am no longer building (from source code) and hosting the MySQL binary packages because the people at MySQL started to provide very nice official binary packages. I am however still providing and updating this set of installation instructions.
Installation Instructions
The first step is to download the software from the mysql.com site. First go to the downloads page at http://dev.mysql.com/downloads/mysql/4.1.html. Download the Standard
installer package in the Mac OS X downloads
section.
Installation Procedure
NOTE: You must have administrator rights to perform this installation.
Do this to install for the first time (see below for update instructions):
Mac OS version 10.2 and higher
- Download the package mentioned above to your desktop. Unpack it and then double-click on the .pkg file to install it.
- Open a terminal window and type in the following commands (without the double quotes):
- type
cd /usr/local/mysql - type
sudo chown -R mysql data/, enter your Mac OS X account password when asked for it. - To start the server, issue
sudo echofirst, then typesudo ./bin/mysqld_safe & - Use it with
/usr/local/mysql/bin/mysql test
/usr/local/mysql/bin in front of every single mysql-related command, then you have to add the /usr/local/mysql/bin directory to your PATH environment variable in your shell's login script.
For the tcsh shell, which was the default up to Mac OS X 10.2 , you can do this by running this command once:
echo 'setenv PATH /usr/local/mysql/bin:$PATH' >> ~/.tcshrc
For the bash shell, which is the default for new user accounts created under Mac OS X 10.3, the command is:
echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
After performing the above steps, read the section about User Account Management in the manual carefully, it explains how to set up permissions etc.
Important: You should at least run this command in order to secure the open master account in the default installation:
/usr/local/mysql/bin/mysqladmin -u root password new_password_here
In recent distributions of MySQL, you can also run the script mysql_secure_installation instead of just
changing the root password. That script allows you to change the root password, delete the test database, remove the anonymous user,
remove remote access (allowing access from the local machine only) and reset the privileges table.
Database Re-Initialization
Sometimes the scripts in the installer package do not work correctly, preventing the startup of the database server. Sometimes you need to reinitialize for other reasons, when the database is too screwed up. So if you have problems and you want a fresh start
, perform these steps manually and then try again to start the server:
sudo find /usr/local/mysql/data -type f -exec rm {} ';'sudo hostname 127.0.0.1cd /usr/local/mysqlsudo ./scripts/mysql_install_dbsudo chown -R mysql data/
Note that you will loose all data stored in the database this way.
Update Instructions
If you previously installed an older version of this package, here is what you have to do to update to the most recent version:
- Type this into a terminal window to save the old data:
cd /usr/local/mysql; sudo tar -cvf /tmp/mysql-data.tar data - Download and unpack the new version of the package
- Install it by double-clicking on the package icon and going through the installer screens
- Type these two commands into a terminal window to restore the old data:
cd /usr/local/mysql; sudo tar -xf /tmp/mysql-data.tar
sudo chown -R mysql /usr/local/mysql/data/* - Reboot the machine
- Unless you have the StartupItem installed, start the DB server again:
- type
cd /usr/local/mysql - type
sudo echofirst, then typesudo ./bin/mysqld_safe &
All your data and settings will be preserved, unless this is a major version update, in which case the table format might have changed (doesn't happen often). In these cases, you have to dump and re-import the data, and you must not do the two lines with the tar command above.
Please note, that after upgrading from MySQL 3.23 to MySQL 4.0 it is recommended to convert the MySQL privilege tables using the mysql_fix_privilege_tables script, since some new security privileges have been added.
Please see http://www.mysql.com/doc/en/Upgrading-from-3.23.html for more information on how to upgrade from MySQL 3.23.
Examples
- TestMySQL.java is a short Java example that shows how to access the DB server using the JDBC interface. You need the JDBC drivers mentioned below.
FAQ
This section list a few frequently asked questions and their answers.
Try this: http://sourceforge.net/forum/message.php?msg_id=198555
Also read this here: http://www.mysql.com/doc/en/Adding_users.html
Check out the Database Re-Initialization
section above.
Sorry, the host 'your_hostname_here' could not be looked up.
Please configure the 'hostname' command to return a correct hostname.There is a problem with the DNS configuration for the IP address you're using. Often, the forward
and reverse
DNS entries for it do not match. This is usually a problem your network administrator or ISP has to fix.
Someone sent me this useful workaround: just type sudo hostname 127.0.0.1, then issue the command again.
ERROR 1148: The used command is not allowed with this MySQL versionwhen I try to use
LOAD DATA LOCAL INFILE?Please read this
undefined reference to _BC expected to be defined in /usr/lib/libSystem.B.dylibwhen I try to use mysql?
You installed the wrong MySQL package (the one I made for Mac OS X 10.1) on a machine running Mac OS X 10.2 (or you never updated MySQL after updating to Mac OS X 10.2).
ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)when I try to connect to the DB using the
mysql command line client?Most likely you didn't start up the DB server. Try this:
cd /usr/local/mysql;
sudo echo
sudo ./bin/mysqld_safe &
Then try to connect again.
mysqld ended when I try to start up the DB server with the safe_mysqld command?Look at the end of the .err file(s) in your mysql data directory.
Whenever you see mysqld ended, these .err files will tell you the exact reason why the server refuses to start up.
You can use the script on the cleanup instructions page.
Look at my InnoDB page.
Additional Information
- CocoaMySQL is a great, full-featured free and open source graphical Cocoa MySQL client.
- YourSQL by Magister Ludi is designed to be "a simple and quick MySQL database client" for OS X.
- Sheri German has a series of very useful tutorials and tips about integrating MySQL with GoLive
- make_mysql_pkg.pl is a Perl script to create the binary distribution package without Apple's Package Maker. This is useful to create the package when no GUI access is available to the machine on which the build is performed.
- MM.MySQL is a free JDBC driver
- DBI and DBD::mysql are Perl modules for interfacing with MySQL from your Perl code
- Brian DePalo has created a password-setter utility for MySQL (Link seems to be dead unfortunately...)
- The Business Mac has a feature on installing MySQL as well as introductions to relational databases and the SQL language.
- Erik Wrenholt wrote a nice, simple PHP application to get you started with PHP and MySQL
- phpMyAdmin is a web-based (PHP) administration front end for mysql. I've heard good things about it but never used it myself.
- DbVisualizer is a great free graphical front end for various databases
- SQLBoss is a commercial graphical front end for various databases, among them MySQL...
- MacSQL is a graphical front-end to PostgreSQL and MySQL
- Here is an introduction to SQL
- Jeroen Clarysse suggests the program Cyclone for converting Mac-Roman encoded text to the ISO character set, which is what these programs expect as input. For example, this might be useful if you move your data from FileMaker to one of these databases.
Build Instructions
Here are the general steps needed to create the package from source.
- Download the source from www.mysql.com and unpack it.
- Download, build and install the software / libraries for which you would like to include support in your module.
- configure the source, my configure line reads
./configure --mandir=/usr/local/share/man/ --with-innodb - Build using
make, wait until finished, then do asudo make install.
