I'm trying to install mysql and mariadb on the same server as a parallel installation, each service on a different port.

I installed mysql server using apt-get on a debian-based distro and then mariadb following this tutorial using mariadb pre-compiled binaries.

At a first glance everything seems to work fine because:

A) I see both services listening on ports 3306 and 3307 after doing "netstat -latun":

    tcp        0      0    *               LISTEN     
    tcp        0      0  *               LISTEN     
    tcp        0      0  *               LISTEN     
    tcp6       0      0 :::80                   :::*                    LISTEN     
    tcp6       0      0 :::22                   :::*                    LISTEN 

B) From a remote host I can connect to both services via phpMyAdmin and via command line and execute queries:

MySQL: mysql -u root -pmypassword -h x.x.x.x --port 3306

MariaDB: mysql -u root -pmypassword -h x.x.x.x --port 3307

C) On the server I can successfully connect to both consoles and execute queries using:

MySQL: mysql -u root -pmypassword --port 3306

MariaDB: mysql -u root -pmypassword --socket=/opt/mariadb-data/mariadb.sock

What's not working

Cannot connect like this:

/opt/mariadb/bin/mysql -u root -pmypassword --port 3307
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2 "No such file or directory")

Connects to port 3306 instead:

/usr/bin/mysql -u root -pmypassword --port 3307

I believe that as a consequence of the previous errors my Joomla installation works only when mysql is up running either on port 3306 or 3307.

When only MariaDB is up running on either port Joomla displays:

Database connection error (2): Could not connect to MySQL.Database connection error (2): Could not connect to MySQL. 

and command line:

# /usr/bin/mysql -u root -pmypassword
ERROR 2002 (HY000): Can't connect to local MySQL server through    socket '/var/run/mysqld/mysqld.sock' (2)

# /opt/mariadb/bin/mysql -u root -pmypassword
ERROR 2002 (HY000): Can't connect to local MySQL server through  socket '/tmp/mysql.sock' (2 "No such file or directory")

When MariaDB is running I still can connect via phpMyAdmin and command line from a remote host or via command line on the server using the --socket option.

I have to notice though that during previous tests, starting from a mysql installation I installed mariadb-server via apt-get and it replaced the mysql installation and everything worked fine either via command line or via any php cms framework for that matter.

I think there are still references to mysql somewhere, to its socket file in particular because using --socket option through command line makes it work everytime

At this point I believe apache and php come into the picture but don't know yet where to dig.

Bottom line:

  • From a remote host phpMyAdmin and command line work with every service on either port.
  • On the server Apache and php do not connect to MariaDB on either port
  • Connect to MariaDB via command line on the server only works if --socket option is given.

While I research on this matter, is there any suggestion?

Thank you very much.

  • Try -h with address or ::1 -- not name localhost even though that is normally the same -- or explicitly --protocol=TCP. I don't have mariadb doc, but it's mostly compatible with mysql and mysql -h localhost or omitted uses the socket not TCP even if you specify -P see dev.mysql.com/doc/refman/5.7/en/connecting.html -- and I wouldn't be surprised if they default to the same socket location. – dave_thompson_085 Dec 11 '15 at 13:39

Found a partial solution to this problem

Apache, PHP and therefore other CMS can connect just fine now.

Edit file /etc/php5/apache5/php.ini and depending on which driver you used (mysql or mysqli) set the corresponding variables to use the socket file used by MariaDB:

    mysql.default_socket =/opt/mariadb-data/mariadb.sock


    mysqli.default_socket =/opt/mariadb-data/mariadb.sock

So for convenience you should now have three php.ini files:

    php.ini, php.ini.mysql,php.ini.mariadb

and overwrite php.ini with either one of the two other file when you plan to use the corresponding database service and restart apache. You can now leave CMS configuration untouched except for ports of course.

This way you can install mariadb on an existing production server with an already existing mysql installation. Without outaging service you can export databases from mysql and importing them into mariadb; at this point either you change CMS (Joomla in my case) configuration to point to a different port or you overwrite php.ini as shown above and restart/reload apache.

Hope it helps gang! It saved my day :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.