Error installing RMySQL to run in Docker on Mac OS X - mysql

I am trying to run MySQL in an R script running inside a Docker (actually Rocker) container, but am getting an error on the “install_packages(…” step. The only solution I found that was somewhat similar was specific to running RedHat Linux (I am running Mac OS X 10.15) and the solution included pointing to several directories that I do not have. Running under RStudio or from the command line, RMySQL loads without a problem.
Dockerfile:
FROM rocker/r-ver:latest
RUN mkdir /home/analysis
COPY install_packages.R /home/analysis/install_packages.R
COPY script_basic.R /home/analysis/script_basic.R
RUN Rscript /home/analysis/install_packages.R
CMD Rscript /home/analysis/script_basic.R
R files:
script_basic.R
library( RMySQL )
install_packages.R
install_packages(“RMySQL”)
Commands and responses:
$ docker build -t myapp .
…
Successfully tagged myapp:latest
$ docker run -it --rm myapp
Loading required package: DBI
Error: package or namespace load failed for ‘RMySQL’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/RMySQL/libs/RMySQL.so':
libmysqlclient.so.21: cannot open shared object file: No such file or directory
Execution halted
$

I believe that rocker/r-dev does not include the libraries you need to get this to run. Untested, but try something like this.
Dockerfile
FROM rocker/r-ver:latest
RUN mkdir /home/analysis
RUN apt-get update \
&& apt-get install -y --no-install-recommends libmariadbclient-dev
COPY install_packages.R /home/analysis/install_packages.R
COPY script_basic.R /home/analysis/script_basic.R
RUN Rscript /home/analysis/install_packages.R
CMD Rscript /home/analysis/script_basic.R
You can find the need for certain libraries on https://cran.r-project.org/web/packages/RMySQL/index.html, as
SystemRequirements: libmariadb-client-dev | libmariadb-client-lgpl-dev | libmysqlclient-dev (deb), mariadb-devel (rpm), mariadb | mysql-connector-c (brew), mysql56_dev (csw)
and a note on how to install them in RMySQL's github README.md's Installation section.
(The CRAN page references libmysqlclient-dev, but the github page suggests "the mariadb implementation is much better". I don't know the premise of the statement, just explaining why I suggested one and CRAN listed another.)

Related

how to install mysql to existing docker file

I'm trying to add mysql to a dockerfile. I dont want to use a mysql source docker, I'm using something else as I need ffmpeg/nvidia/asp.net aswell. So I can't simple use a different base image to start from.
So how can I
Add mysql to my docker build file?
Configure it so the data for mysql is in a specific directory (so I can can map outside the docker file)
Have mysql start up but not be the entry point service
Everything I found so far basically say "use this base image". which doesn't help me. I dont want to have mysql separate, just self contained docker image with everything it needs.
TIA
Install mysql
Use apt-get to install packages on debian distro's. Add in your dockerfile the following line:
RUN apt-get update && apt-get install -y mysql-server
Start MySQL
Add to the Dockerfile CMD a prefix where you start mysql in detached mode. Like:
CMD mysql start & # [paste here your default command]`.
This will start mysql and start your app.
Mount directories
Mounting directories is done with the -v flag:
docker run -ti -v <host_dir>:<container_dir> my-image /bin/bash

How to use SwiftMySQLKuery with tools-utils.sh on the official swift-ubuntu image?

I'm trying to run a release build of my kitura (2.7) app with mysql on the official swift-ubuntu (latest, 5.0.1) image with the following commands.
docker build --no-cache -t my-app-build -f Dockerfile-tools .
docker run -v $PWD:/swift-project -w /swift-project my-app-build /swift-utils/tools-utils.sh build release
First command one is working as expected. Second one is giving a warning:
warning: you may be able to install mysqlclient using your system-packager: apt-get install libmysqlclient-dev
Tried to install the lib but nothing changed...
Can someone help me?
Thanks in advance!
The issue appears to be related to the version of Ubuntu and the resulting level of MySQL that is installed. As the base container is running Ubuntu 14.04 when MySQL installs you get version 5.5 which does not ship the required configuration for pkg-config to find the include paths needed to build your application.
I have been able to get a simple Kitura application which uses SwiftKueryMySQL to build under docker by updating my Dockerfile-tools file with two changes:
1) Update the FROM to:
FROM swift:5.0.1
2) Add some required packages:
# Install system level packages
RUN apt-get update && apt-get install -y sudo libcurl4-openssl-dev openssl libssl-dev pkg-config libmysqlclient-dev
With these updates your build should succeed. I will look into a longer term solution to the issue.

Installation Requirements for mysql with DBIish on rakudo-star docker image

I was creating an own docker image based on the latest rakudo-star docker image. I wanted to use DBIish to connect to a mysql database. Unfortunately I am not able to get the DBDish::mysql to work.
I've installed default-libmysqlclient-dev as you can see in
# find / -name 'libmysqlclient*.so'
/usr/lib/x86_64-linux-gnu/libmysqlclient_r.so
/usr/lib/x86_64-linux-gnu/libmysqlclient.so
The error i am facing is:
# perl6 -Ilib -e 'use DBDish::mysql; DBDish::mysql.connect()'
Cannot locate native library 'mysqlclient': mysqlclient: cannot open shared object file: No such file or directory
in method setup at /usr/share/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03 (NativeCall) line 289
in method CALL-ME at /usr/share/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03 (NativeCall) line 539
in method connect at /root/DBIish/lib/DBDish/mysql.pm6 (DBDish::mysql) line 12
in block <unit> at -e line 1
Short answer: you need the package libmysqlclient20 (I added the documentation request to a similar DBIish issue). Debian 9 (stable at the moment) uses and older version than Ubuntu 18.04 (stable at the moment) and Debian Unstable. It also refers to mariadb instead of mysql. Pick libmariadbclient18 on images based on Debian Stable and create a link with the mysql name (see below).
On Debian Testing/Unstable and recent derivatives:
$ sudo apt-get install libmysqlclient20
$ dpkg -L libmysqlclient20
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.9
/usr/share
/usr/share/doc
/usr/share/doc/libmysqlclient20
/usr/share/doc/libmysqlclient20/NEWS.Debian.gz
/usr/share/doc/libmysqlclient20/changelog.Debian.gz
/usr/share/doc/libmysqlclient20/copyright
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
On Debian 9 and derivatives:
$ dpkg -L libmariadbclient18
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18.0.0
/usr/lib/x86_64-linux-gnu/mariadb18
/usr/lib/x86_64-linux-gnu/mariadb18/plugin
/usr/lib/x86_64-linux-gnu/mariadb18/plugin/client_ed25519.so
/usr/lib/x86_64-linux-gnu/mariadb18/plugin/dialog.so
/usr/lib/x86_64-linux-gnu/mariadb18/plugin/mysql_clear_password.so
/usr/share
/usr/share/doc
/usr/share/doc/libmariadbclient18
/usr/share/doc/libmariadbclient18/changelog.Debian.gz
/usr/share/doc/libmariadbclient18/copyright
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18
Create the link:
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libmariadbclient.so.18 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
In order to illustrate this, I created an Ubuntu 18.04 container for the occasion*:
docker run -ti --rm --entrypoint=bash rakudo/ubuntu-amd64-18.04
And the abbreviated commands and output:
# apt-get install -y libmysqlclient20 build-essential
# zef install DBIish
# perl6 -e 'use DBDish::mysql; DBDish::mysql.connect()'
Cannot look up attributes in a DBDish::mysql type object
[...]
The error is because I didn't pass the correct parameters for connect as I didn't have a db running. The important thing is that no .so file is missing.
*: I uploaded it to the Docker Hub, a normal run will put you right in the REPL:
$ docker run -ti --rm rakudo/ubuntu-amd64-18.04
To exit type 'exit' or '^D'
>
(I didn't use the Star image when debugging, but it does not matter because this is a more generic problem.)

Unable to run startup script when creating instance on Google Cloud Platform

I have a simple startup script which looks like so:
#!/usr/bin/env bash
sudo apt update
sudo apt install -y ruby-full ruby-bundler build-essential
And create VM instance on GCP like so:
$ gcloud compute instances create test-app --boot-disk-size=10GB --image-family ubuntu-1604-lts --image-project=ubuntu-os-cloud --machine-type=g1-small --zone europe-west1-b --tags test-server --restart-on-failure --metadata-from-file startup-script=startup.sh
My startup.sh is executable. I set its rights like so:
$ chmod +x startup.sh
When however I enter the shell of my newly created instance and check bundler:
test-app:~$ bundle -v
I get these messages:
The program 'bundle' is currently not installed...
So, what is wrong with that and how can I fix it? PS. If I run all my commands just from inside the instance shell, it's all ok, so there is some problem with using startup script on GCP.
I tested with your use case, But the bundle package was installed without making any changes.
Output:
bundle -v
Bundler version 1.11.2
You can check VM serial console log output to verify if start-up script ran. Check the VM instance to verify if the package is installed using the commands below:
sudo apt list --installed | grep -i bundle
sudo egrep bundle /var/log/dpkg.log
In addition, check the gem list bundle

Installing Levenstein Functions on centos 6 cloud server

I'd like to install the following UDF's from sam J levy's site
I have run through the windows (32 bit) installation with wamp for my testing server with no problem. Now I have my proper server running centOs 6.4. I have copied the .so files to
usr/lib64/mysql/plugin/damlev.so
I then try to run one of the sql statements to create the function
CREATE FUNCTION damlev RETURNS INTEGER SONAME 'damlev.so';
And get the following error
1126 - Can't open shared library 'damlev.so' (errno: 22 /usr/lib64/mysql/plugin/damlev.so: wrong ELF class: ELFCLASS32)
What Am I doing wrong. Is it because the server is 64bit?
Edit Bounty Started:
If more details about the server are required I can gladly supply them. I need this function installed.
It seems that you're trying to use the damlev.so library included in the damlev.zip file of the Levi's site, but that library is for an Ubuntu 32-bit system, therefore it cannot work on your Centos 64-bit system, so you'll have to compile from sources.
As a prerequisite, you must install the g++ compiler and the mysql development libraries:
yum install gcc-c++ mysql-devel
Also, if you don't have wget and unzip, install them with the following command:
yum install wget unzip
Then download the source code and unzip it somewhere:
cd tmp
mkdir damlev
cd damlev
wget http://samjlevy.com/wp-content/uploads/2011/03/damlev.zip
unzip damlev.zip
cd src
Finally compile, install the plugin and restart the mysql server:
g++ -fPIC -I /usr/include/mysql/ -o damlev.so -shared damlev.cpp
cp damlev.so /usr/lib64/mysql/plugin/
service mysql restart
Please note that all the above command must be run as "root".