[Nix-dev] How to use MySQL

Tomasz Czyż tomasz.czyz at gmail.com
Mon Oct 3 10:33:24 CEST 2016


By looking at errors you pasted I assume you are not using proper
configuration or default configuration is used when you don't provide any.
And by default probably paths are set to /var/lib which is writeable only
by root or system services.

To run mysql in userspace you need to adjust all those paths in your
configuration to point to directories accessible/writeable by user.

I'm not sure if this actually worth the effort.

You could try to run mysql using nixos-container, so you run mysql as
"service" but in container and you can start/stop the container whenever
you want (and it's easier to start because you can use system level
"service" inside).

2016-10-03 9:30 GMT+01:00 Tomasz Czyż <tomasz.czyz at gmail.com>:

> Linus,
>
> by installing it with nix-env you install only the binary and all
> application execution is in user hands. By using "service" in
> configuration.nix you actually start a daemon (like /etc/init.d/mysql in
> ubuntu for instance).
>
> If you want to start it in user space you have to follow exactly the same
> steps as in other distros when you are not using /etc/init.d/ or upstart or
> whatever system level daemon manager.
>
> If you want to try to reproduce what "service" is doing in your userspace,
> you can check config of service and try to execture those commands in
> userspace:
>
> https://github.com/NixOS/nixpkgs/blob/master/nixos/
> modules/services/databases/mysql.nix
>
> So you can see, that configuration is generated first and then service is
> started with
>
> serviceConfig.ExecStart = "${mysql}/bin/mysqld
> --defaults-extra-file=${myCnf} ${mysqldOptions}";
>
>
> 2016-10-03 9:21 GMT+01:00 Linus Arver <linusarver at gmail.com>:
>
>> Hello all,
>>
>> I want to install and use MySQL on NixOS, but am not sure how to
>> proceed. I've managed to do
>>
>>     nix-env -iA nixos.mysql55
>>
>> but trying to get it to run is difficult. Here is what I tried:
>>
>>     [月 03 0:50:47] - l_k0 ~/prog/sqfmm/mysql
>>      > mysql
>>     ERROR 2002 (HY000): Can't connect to local MySQL server through
>> socket '/run/mysqld/mysqld.sock' (2)
>>     [月 03 0:50:53] 1 - l_k0 ~/prog/sqfmm/mysql
>>      > systemctl start mysqld
>>     ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
>>     Authentication is required to start 'mysqld.service'.
>>     Multiple identities can be used for authentication:
>>      1.  System administrator (root)
>>      2.  Linus Arver (l)
>>     Choose identity to authenticate as (1-2): 2
>>     Password:
>>     ==== AUTHENTICATION COMPLETE ===
>>     Failed to start mysqld.service: Unit mysqld.service not found.
>>     [月 03 0:52:33] 5 - l_k0 ~/prog/sqfmm/mysql
>>      > systemctl start mysql
>>     ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
>>     Authentication is required to start 'mysql.service'.
>>     Multiple identities can be used for authentication:
>>      1.  System administrator (root)
>>      2.  Linus Arver (l)
>>     Choose identity to authenticate as (1-2): 2
>>     Password:
>>     ==== AUTHENTICATION COMPLETE ===
>>     Failed to start mysql.service: Unit mysql.service not found.
>>     [月 03 0:52:57] 5 - l_k0 ~/prog/sqfmm/mysql
>>      > mysqld
>>     161003  0:53:16 [Note] mysqld (mysqld 5.5.50) starting as process
>> 12363 ...
>>     161003  0:53:16 [Warning] Can't create test file
>> /var/lib/mysql/k0.lower-test
>>     161003  0:53:16 [Warning] Can't create test file
>> /var/lib/mysql/k0.lower-test
>>     mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 2)
>>     161003  0:53:16 [ERROR] Aborting
>>
>>     161003  0:53:16 [Note] mysqld: Shutdown complete
>>
>>     [月 03 0:53:16] 1 - l_k0 ~/prog/sqfmm/mysql
>>      > mysqld_safe
>>     161003 00:54:16 mysqld_safe Logging to '/var/lib/mysql/k0.err'.
>>     touch: cannot touch '/var/lib/mysql/k0.err': No such file or directory
>>     chmod: cannot access '/var/lib/mysql/k0.err': No such file or
>> directory
>>     mkdir: cannot create directory ‘/run/mysqld’: Permission denied
>>     chown: invalid user: ‘mysql’
>>     chmod: cannot access '/run/mysqld': No such file or directory
>>     161003 00:54:16 mysqld_safe Starting mysqld daemon with databases
>> from /var/lib/mysql
>>     /home/l/.nix-profile/bin/mysqld_safe: line 128:
>> /var/lib/mysql/k0.err: No such file or directory
>>     /home/l/.nix-profile/bin/mysqld_safe: line 165:
>> /var/lib/mysql/k0.err: No such file or directory
>>     touch: cannot touch '/var/lib/mysql/k0.err': No such file or directory
>>     chown: invalid user: ‘mysql’
>>     chmod: cannot access '/var/lib/mysql/k0.err': No such file or
>> directory
>>     161003 00:54:16 mysqld_safe mysqld from pid file
>> /var/lib/mysql/k0.pid ended
>>     /home/l/.nix-profile/bin/mysqld_safe: line 128:
>> /var/lib/mysql/k0.err: No such file or directory
>>
>> The attempt to run *mysqld_safe* was taken from the official docs at
>> http://dev.mysql.com/doc/refman/5.6/en/starting-server.html.
>>
>> I see that there are several configuration options for MySQL
>> (services.mysql.*) defined in the NixOS manual
>> (https://nixos.org/nixos/manual/options.html#opt-services.mysql.enable)
>> but this seems to be for enabling it as a service that starts
>> unconditionally on every boot (configuration.nix), which I want to avoid.
>>
>> How do I start MySQL without touching configuration.nix? If
>> configuration.nix is the only sane/preferred way to use MySQL on NixOS,
>> then is there a resource/wiki/blogpost that discusses a minimal example?
>> I don't mind trial-and-error with editing my system configs but seeing a
>> second-hand account of the entire process would be very helpful.
>>
>> Please forgive me if I have missed any obvious documentation.
>>
>> Best,
>> Linus
>> _______________________________________________
>> nix-dev mailing list
>> nix-dev at lists.science.uu.nl
>> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>>
>
>
>
> --
> Tomasz Czyż
>



-- 
Tomasz Czyż
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20161003/b554c01e/attachment.html>


More information about the nix-dev mailing list