Search code examples
mysqlalpine-linux

Installing Mysql on a VM under Alpine


I'm trying to install and use mysql on Alpine. I'm using Docker to generate a VM under Alpine. My Dockerfile is really simple :

FROM alpine:3.11.3

CMD sh

Once I've run the image created (using docker build // docker run image_id), I install Mysql :

apk add --update --upgrade mysql mysql-client

Then, I install the database :

mysql_install_db

The problem is that once I've done that and I try to "mysql", the machine returns this :

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)

And when I try to do "mysqld -u root", it returns me this problem :

2020-08-26 10:07:55 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2020-08-26 10:07:55 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
2020-08-26 10:07:55 0 [ERROR] Can't start server : Bind on unix socket: No such file or directory
2020-08-26 10:07:55 0 [ERROR] Do you already have another mysqld server running on socket: /run/mysqld/mysqld.sock ?
2020-08-26 10:07:55 0 [ERROR] Aborting

I understood that the file mysqld.sock serves the server to discuss with the client. I tried to create the directory mysqld and then to create the file mysqld.sock but it doesn't work. It returns me the same error but with a different return value.

(ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (111)

At least, I don't want to use an existing image of mysql on Dockerhub.

Do anybody has an idea of what step is missing to make it work ?

Sorry if I'm not writing proper, I'm not a native english speaker.


Solution

  • I was able to successfully install and start mysql on an alpine container with these commands:

    $ docker run -it --rm alpine:latest
    
    / # apk add mysql mysql-client
    / # mkdir /run/mysqld
    / # mysql_install_db
    / # mysqld -u root --data=./data &> /dev/null &
    

    Testing connection:

    / # mysql -e "SELECT VERSION();"
    +----------------+
    | VERSION()      |
    +----------------+
    | 10.6.4-MariaDB |
    +----------------+