简体   繁体   中英

Cannot start MariaDB after installing alongside MySQL on Ubuntu 14.04

I have installed MariaDB 10.0.14 following the official instructions in mariadb.com line by line.

I'm running Ubuntu 14.04 (upgraded from 12.04) and already have MySQL server installed. When I try to run mariadb I first stop the MySQL service:

$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mariadb start

but nothing happens. Apparently mariadb.sock cannot be created:

$ mysql -e "SELECT VERSION();" --socket=/opt/mariadb-data/mariadb.sock    
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/mariadb-data/mariadb.sock' (111)


My error log is:

141112 13:50:37 mysqld_safe Starting mysqld daemon with databases from /opt/mariadb-data    
141112 13:50:37 [Note] Server socket created on IP: '::'.
141112 13:50:37 [ERROR] mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 "Permission denied")
141112 13:50:37 [ERROR] Can't start server: can't create PID file: Permission denied
141112 13:50:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended


I can't understand why I get permissions denied upon starting the service. I've created new system group and user, both called mariadb, that should handle this, as stated in the instructions.

Perhaps I should grant full r/w rights for my /opt/mariadb-data directory, but I'm not sure this is a good approach. What should I do?

Even though @hartmut-holzgraefe provides a nice solution in his answer, I decided to try a different approach. Since it works really well and independently from my MySQL server I thought I might share it with everybody as well.

Going with a Docker container for MariaDB ( tutum/mariadb ) turns out to be a quicker and perhaps cleaner solution than trying to install it alongside MySQL.

Steps

The steps to run mariadb via docker are:

  1. Install Docker
  2. Pull whichever version of MariaDB you want from tutum-docker-mariadb (in my case 10.1)
  3. Build an image and run it to set up a container


Commands

The commands for step 3 are listed in the repo's README. I'll only mention you may want to explicitly preset the hostname and the port of your machines, like so:

# build the image
docker build -t tutum/mariadb .

# run it
docker run -d -p 127.0.0.1:3307:3306 -e MARIADB_PASS="mypass" tutum/mariadb

# connect to mariadb
mysql -uadmin -pmypass -h127.0.0.1 -P3307


  • admin is a default user created with the initial run of the container
  • mypass is a custom pass to override the random password that is initially generated (otherwise you'd have to use docker logs to get it it)
  • 127.0.0.1:3307:3306 means you are binding the 3306 port inside the container with the 3307 port on you localhost.

Are you sure you got the --defaults-file=/opt/mariadb-data/my.cnf modifications to the /etc/init.d/mariadb correctly applied?

Problem is that mysqld still tries to create the .pid file in /var/run/mysql, not under /opt/mariadb. The /var/run/mysql directory belongs to the "mysql" system user, not the "mariadb" user you created according to the instructions.

And the /var/run/mysql setting can only come from the system /etc/mysql/my.cnf file, which is read by mysqld_safe / mysqld by default, UNLESS this is overridden with --defaults-file=...

Also note that --defaults-file needs to be the very first command line option

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM