How do I set up MySQL?

Note that the department now has a central, departmentally managed SQL server that you may use. Just send email to staff@cs.umd.edu to ask about having a database set up for you on this server.

Or, if you prefer to set up and run your own mysql server, continue with the instructions below...


First figure out where you are going to store your database files. This has to be a directory that you have full read/write privileges to.   Also please be aware that /tmp is not a good place for this, as it could be deleted at anytime when the machine needs space.
Next, create a .my.cnf file in the base of your home directory (${HOME}/.my.cnf). Next fill it with the appropriate information as in the example below, but make sure that the datadir is the directory you picked at the start of this document.  Also make sure that the socket file that you pick is writeable by you.

[derek@nobby ~]$ cat .my.cnf
[client]
socket=/export/home/derek/.mysql.sock
[mysqld]
datadir=/export/home/derek/mysql
socket=/export/home/derek/.mysql.sock

Next run, /usr/local/bin/mysql_install_db as this will fill in all the appropriate tables.
[derek@nobby ~]$ /usr/local/bin/mysql_install_db
Preparing db table
Preparing host table
Preparing func table
Preparing tables_priv table
Preparing colums_priv table
Installing all prepared tables
<snip>
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
This is done with:
/usr/local/mysql-4.0.15/bin/mysqladmin -u root password 'new-password'
<snip>
You can start the MySQL daemon with:
cd /usr/local/mysql-4.0.15 ; /usr/local/mysql-4.0.15/bin/mysqld_safe &
<snip>
  
As you can see you just need to run /usr/local/sbin/mysqld & (do not use mysqld_safe line from above)
[derek@nobby ~]$ /usr/local/sbin/mysqld &
[1] 22403
00628 21:34:32  InnoDB: Started
/usr/local/sbin/mysqld: ready for connections.
Version: '4.0.17'   socket:  '/export/home/derek/.mysql.sock'   port: 3306


Then finally set a root password with, /usr/local/bin/mysqladmin -u root password 'somepassword'

The rest is up to you. Documentation is available at http://www.mysql.com. I also recommend the O'Reilly book "MySQL and mSQL", which is a bit clearer.
Last modified: June 2004