public void startMysql() throws IOException
    {
        ServerSocket socket = new ServerSocket(0);

        port = socket.getLocalPort();
        socket.close();

        dbDir = File.createTempFile("mysqldb", ".db");
        Assert.assertTrue(dbDir.delete());
        Assert.assertTrue(dbDir.mkdir());

        mysqldResource = new MysqldResource(dbDir);

        Map<String, String> dbOpts = new HashMap<String, String>();

        dbOpts.put(MysqldResourceI.PORT, Integer.toString(port));
        dbOpts.put(MysqldResourceI.INITIALIZE_USER, "true");
        dbOpts.put(MysqldResourceI.INITIALIZE_USER_NAME, USERNAME);
        dbOpts.put(MysqldResourceI.INITIALIZE_PASSWORD, PASSWORD);

        mysqldResource.start("test-mysqld-thread", dbOpts);

        if (!mysqldResource.isRunning()) {
            throw new IllegalStateException("MySQL did not start.");
        }
    }