Creating a Local Mokka Geometry Database

  1. First, make sure that the MySQL-related commands are accessible through your PATH. If MySQL is not installed at a standard location such as /usr/bin, you have to adjust the environment variable PATH, either interactively or in a shell initialisation file:

    export PATH=your_mysql_installation/bin:${PATH}

    Replace your_mysql_installation by the path to your local MySQL installation. In case you get an “error while loading shared libraries”, you may need to include your_mysql_installation/lib/mysql in the environment variable LD_LIBRARY_PATH.

    At DESY, the latest version for Scientific Linux 4 (as of April 2008) can be found at /opt/products/mysql/5.0.45. The server-side software (mysql_install_db and mysqld_safe) can be found only in /opt/products, but the client-side software (mysql, libmysqlclient, …) is also available locally under /usr/bin. Note that a version mismatch between server and client will generally not be a problem.

  2. Create a data directory:

    mkdir your_data_directory

    Replace your_data_directory by a path of your choice, for example /data/${USER}/mysql. You will need a few megabytes of disk space. Avoid directories in the AFS, because your AFS token will expire after a day, at the latest. Do not choose a directory inside /tmp, either, because such data may automatically be erased by the system after some time.

  3. Initialise the local database. This will create some directories and files in your data directory that are used internally by MySQL:

    cd your_mysql_installation
    bin/mysql_install_db --datadir=your_data_directory

    Note that this script has to be called from the installation directory in some versions of MySQL. Don’t be alarmed by the bunch of appearing messages – we’ll take care of the MySQL root password in a second.

  4. Start the MySQL daemon in the background, using your data directory. It may take a moment until it is up and running. If you get an error message about insufficient permissions, you can try the option --no-defaults as the first argument.

    bin/mysqld_safe --datadir=your_data_directory &
    cd -

    Note that the daemon was called safe_mysqld in earlier versions of MySQL. It has to be running whenever you want to access your local database. If you use a program like top, you will see that the daemon spawns a couple of processes named mysqld which you don’t need to worry about. It also creates a socket file in the /tmp directory, which you should not delete. (You can specify another location or name with the --socket option.)

  5. Enter the MySQL monitor and change some access rights for your local database: Choose a root password, delete the anonymous user, and create a user consult with password consult to be used by Mokka.

    mysql -uroot
    UPDATE mysql.user SET Password=PASSWORD('mysql_root_password') WHERE User='root';
    UPDATE mysql.user SET Host='your_long_hostname' WHERE Host='your_short_hostname';
    DELETE FROM mysql.user WHERE User='';
    GRANT SELECT ON *.* TO consult@localhost IDENTIFIED BY 'consult';
    GRANT SELECT ON *.* TO consult IDENTIFIED BY 'consult';

    Replace mysql_root_password by a password of your choice. your_short_hostname is the output of the command “hostname --short”, your_long_hostname is the output of “hostname --long”. Remember to terminate MySQL commands with a semicolon. Capitalisation of MySQL keywords is not mandatory, but it will not hurt, either.

  6. Download a dump of the central Mokka geometry database from the LDC Optimisation pages at DESY. Import the the dump file into your local database:

    mysql -uroot -p < your_dump_file

    You will be prompted for the MySQL root password. Note that the dump file is just an automatically generated sequence of MySQL commands and some comments, so it can simply be fed into MySQL using input redirection. After that, you may remove your dump file if you like. Use the same command to extend your local database with data from other dump files, if desired.

  7. Mokka version 05-00 introduces so-called “super drivers” which need some temporary databases for their calculations. Your dump should already have provided these databases, but you still need to grant certain access privileges to the user consult. One table in the database models03 is used to manage the access to these temporary databases – you need to enable consult to lock and modify this table, too.

    mysql -uroot -p
    -- if you use MySQL 3, please ignore the message: Unknown command '\_'.
    GRANT LOCK TABLES ON `models03`.* TO 'consult'; -- for MySQL 4.0 and higher
    GRANT UPDATE ON `models03`.`tmp_databases` TO 'consult';
  8. You should now be ready to run Mokka with your local geometry database. Adjust the corresponding setting in your Mokka steering file:

    /Mokka/init/dbHost your_mysql_host

    Replace your_mysql_host by the name (or IP address) of your host (to connect via TCP) or by the special name localhost (to connect locally via a Unix socket). You can also use the extended notation host:port or localhost:/path/to/socket for more control.

  9. In case you want to stop the MySQL daemon at some later time, use mysqladmin:

    mysqladmin -uroot -p shutdown

    After entering the MySQL root password, the daemon will come to a halt. Use mysqld_safe to restart it. Note that you do not need to stop the daemon before you log out – it can continue running in the background without you being logged in, even though you will still be the owner of the process.

This page is valid XHTML — Last change: 2008-09-01 by Adrian Vogel <>