Initialize MySQL database as non-root and run SQL server for testing

2

I want to do some MySQL-specific testing and need to run a fresh MySQL database as non-root user. I am using Debian Linux and expect one could start the mysql_install_db and other commands as normal user with the right options and writable locations.

  1. Does this work?

  2. How to do it?

I don't want to download software from the MySQL website. Instead I want to use the executables provided by the already installed OS packages. The reasoning is this:

  1. The software is already installed--installing new software from the net is pointless, slow, might fail, possibly a security risk etc. To my knowledge KDE is doing something similar for its data storage.

  2. If it does eventually work I want to wrap the test in a portable script that runs on any computer where mysql_install_db etc. are available.

I searched the web for tutorials/hints but only found loads of descriptions on how to install the software from scratch. With information from what I had read I then tried this:

mkdir ~/tmp/mysql/
mkdir ~/tmp/mysql/mysql/
mkdir ~/tmp/mysql/sql_data/

mysql_install_db \
    --defaults-file=my.cnf
    --user=daniel
    --basedir=/home/daniel/tmp/mysql/mysql/
    --datadir=/home/daniel/tmp/mysql/sql_data/
    --socket=/home/daniel/tmp/mysql/socket

But it complains:

FATAL ERROR: Could not find my_print_defaults

The following directories were searched:

   /home/daniel/tmp/mysql/mysql//bin
   /home/daniel/tmp/mysql/mysql//extra

UPDATE: I still didn't find a solution to limiting the output to error messages. I get many lines with the tag [Note] but didn't find an argument to set debug output level.

Daniel Böhmer

Posted 2016-03-28T23:56:00.950

Reputation: 585

I found a source for my belief in the Akonadi FAQ under Do I need a running MySQL server? and probably the relevant source code in src/server/storage/dbconfigmysql.cpp

– Daniel Böhmer – 2016-03-29T14:29:37.883

What's in /home/daniel/tmp/mysql/mysql/bin at the beginning of this process? Anything? – Michael - sqlbot – 2016-03-30T01:15:45.083

@Michael-sqlbot: The directories bin and extra don't exist. I updated my question to reflect which directories I created. As you see I created them from scratch. They're empty. – Daniel Böhmer – 2016-03-30T08:54:39.513

Answers

0

I found similar calls in the Akonadi code and started to build the commands from scratch while consulting the respective help texts. It looks like I just included useless/counterproductive options before. This did now work for me:

mysql_install_db                    \
  --defaults-file=/dev/null         \ # don't user my.cnf in /etc/ or ~/
  --datadir=/home/daniel/tmp/mysql/ \ # use given directory for data
  --force                             # make mysqld work without /usr/bin/resolveip

I seem to need only 1 directory for data. Setting basedir only works if you provide a complete MySQL installation.

After this I could run the MySQL server:

mysqld                              \
  --defaults-file=/dev/null         \ # as above
  --datadir=/home/daniel/tmp/mysql/ \ # as above
  --socket=/home/daniel/tmp/socket  \ # use writable socket
  --skip-networking                   # for my purposes: only socket connections

Daniel Böhmer

Posted 2016-03-28T23:56:00.950

Reputation: 585