Vagrant Box - Install MySql 5.7 using apt - mysql

I created a basic vagrant box based on ubuntu/trusty64.
When i "vagrant up" the machine and next "vagrant ssh" into it, everything is fine.
Next step would be to install latest mysql 5.7, so thats what i did:
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update
sudo apt-get install -y mysql-server
So it downloads configures etc... next an "interactive" shell appears, where are i am requested to type password and repeat.
MySql 5.7 is installed successfully in my machine...BUT:
I would like it to be installed during "vagrant up", thats why i modified Vagrantfile with:
config.vm.provision :shell, path: "bootstrap.sh"
In bootstrap.sh i added content:
wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update
sudo apt-get install -y mysql-server
This fails completely... in console i can read it tries to configure mysql 5.5 and its dependencies.
But why?
If anybody could help with this issue, i would be really thankful.
Thanks and Greetings!
UPDATE
error message
==> default: There are no enabled repos.
==> default: Run "yum repolist all" to see the repos you have.
==> default: You can enable repos with yum-config-manager --enable <repo>
==> default: sudo: yum-config-manager: command not found
==> default: There are no enabled repos.
==> default: Run "yum repolist all" to see the repos you have.
==> default: You can enable repos with yum-config-manager --enable <repo>
==> default: mysqld: unrecognized service
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

The reason why vagrant is installing 5.5 instead of 5.7 is because ubuntu/trusty version might be ubuntu 14.04, default mysql version for ubuntu 14.04 is mysql 5.5.
Below is a vagrant file which automatically installs mysql 5.7, but I have configured centos6 here. Feel free to change the os and set that to ubuntu/trusty. Just do
mysql57_config.vm.box = 'ubuntu/trusty64'
Instructions:
mkdir mysql-5-7
cd mysql-5-7
Once you are in mysql-5-7 directory add these two files, Vagrantfile and bootstrap.sh file
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "centos/7"
config.vm.hostname = "mysql57"
config.vm.provision "shell", path: "bootstrap.sh"
config.vm.define "mysql57" do |mysql57|
end
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
bootstrap.sh
sudo yum install -y wget
wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
sudo yum install -y mysql57-community-release-el7-8.noarch.rpm
sudo yum -y update
sudo yum -y install mysql-server
sudo systemctl start mysqld
sudo systemctl enable mysqld
MYSQL_TEMP_PWD=`sudo cat /var/log/mysqld.log | grep 'A temporary password is generated' | awk -F'root#localhost: ' '{print $2}'`
mysqladmin -u root -p`echo $MYSQL_TEMP_PWD` password 'Passw0rd!'
cat << EOF > .my.cnf
[client]
user=root
password=Passw0rd!
EOF
Now please run below commands:
vagrant up
vagrant ssh
Ones you are in the machine connected to mysql: connect to mysql and provide below credentials~~
user: root
password: Passw0rd!
Somewhere in /etc/sudoers (or /etc/sudoers.d if it's included) you have to have
vagrant ALL=(ALL) NOPASSWD:ALL
Defaults:vagrant !requiretty
without that, the vagrant ssh (without tty) fails mysteriously.
If you are using MacOS, turn Off firewall and see it this works?

Related

Missing mysql on /etc/init.d/ directory

I've been trying to install mysql using WSL and I've followed the steps indicated in this guide https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database. I tried running mysql --version and it worked (prompted mysql Ver 8.0.23 for Linux on x86_64 (MySQL Community Server - GPL)). But as I try the next command sudo /etc/init.d/mysql start, it says sudo: /etc/init.d/mysql: command not found. I've also tried checking the contents of /etc/init.d/ directory and there is no existing mysql file/folder there. What should I do next to proceed with my mysql installation?
Thanks!
There is a great blog post on this problem, with explanations of the issue and detailed solutions.
https://www.58bits.com/blog/2020/05/03/installing-mysql-80-under-wsl-2-and-ubuntu
From the post:
One solution is to download the mysql.server.sh script from here -
https://github.com/mysql/mysql-server/tree/8.0/support-files - and
then copy and rename the script to /etc/init.d/mysql (make sure that
it's also executable - chmod +x mysql)
You'll then need to set the default values for basdir, datadir and pid
file locations.
Here's an excerpt with the top portion of the file and the settings
that worked for me...
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
basedir=/usr
datadir=/var/lib/mysql
# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900
# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=/var/run/mysqld/mysqld.pid
if test -z "$basedir"
After this you should be able to start and stop MySQL as follows:
sudo service mysql start
sudo service mysql stop
As he mentions later, you also need to create /var/run/mysqld/ and set permissions:
sudo mkdir /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

Ubuntu Linux 18.04 WSL in Windows: MariaDB service start fails

After installing MariaDB repository configuration tool for the first time in my Linux WSL for Windows (as described in MariaDB Download Page), I executed mysql but there was a socket error. netstat -apn | grep mysql shows nothing, indicating the mysql service is stopped; sudo apt list | grep *mysql-server* shows I had successfully installed mysql-server.
However, as I tried sudo service mysql start, the command line gives:
* Starting MariaDB database server mysqld [fail]
I tried the following methods, but all failed and yielded the same answer:
Using /etc/init.d/mysql start
Removing /var/lib/mysql/ib_logfile0 and /var/lib/mysql/ib_logfile1
Upgrading access of /var/lib/mysql using chmod -R 777 /var/lib/mysql
Removing everything from /var/lib/mysql/
Changing port setting using port=1112 in /etc/my.cnf (since I have another mysql on the Windows side)
Filling in additional information in /etc/my.cnf (my configuration file was initially empty after installation, and I filled in the basedir, datadir, socket, log_error, and pid-file properties)
Trying systemctl instead of service (this failed because Linux WSL uses sysvinit instead of systemd)
How could I start my MariaDB service? Thanks
I'm able to reproduce your problem (or one that looks an awfully lot like it) on WSL1. Can you confirm that you are using WSL1?
I spun up two cloned instances (wsl --import of a clean backup) of Ubuntu 20.04 -- One on WSL1 and the other on WSL2. Unfortunately, I don't have a handy 18.04 to work with, but I'm hoping the problem is the same.
On WSL2, everything worked properly. After the installation steps (pretty much the ones you put in your comment, but for 20.04), I was able to:
sudo service mariadb start
and then sudo mysql -u root successfully.
On WSL1, however, the MariaDB installation seems to fail in a strange way. It does not create /etc/mysql/mariadb.cnf, which leads to what you saw with an empty /etc/mysql/my.cnf, since it's a symlink to mariadb.cnf.
So I created mariadb.cnf manually:
sudo vi /etc/mysql/mariadb.cnf
with the contents:
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
This is simply the default mariadb.cnf that was created correctly by the installation on WSL2.
Attempting to start the service then gave an error about a missing /etc/mysql/debian-start, so I repeated the same steps of copying it over:
sudo vi /etc/mysql/debian-start
With the contents:
#!/bin/bash
#
# This script is executed by "/etc/init.d/mariadb" on every (re)start.
#
# Changes to this file will be preserved when updating the Debian package.
#
# NOTE: This file is read only by the traditional SysV init script, not systemd.
#
source /usr/share/mysql/debian-start.inc.sh
# Read default/mysql first and then default/mariadb just like the init.d file does
if [ -f /etc/default/mysql ]; then
. /etc/default/mysql
fi
if [ -f /etc/default/mariadb ]; then
. /etc/default/mariadb
fi
MYSQL="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf"
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
# Don't run full mysql_upgrade on every server restart, use --version-check to do it only once
MYUPGRADE="/usr/bin/mysql_upgrade --defaults-extra-file=/etc/mysql/debian.cnf --version-check"
MYCHECK="/usr/bin/mysqlcheck --defaults-file=/etc/mysql/debian.cnf"
MYCHECK_SUBJECT="WARNING: mysqlcheck has found corrupt tables"
MYCHECK_PARAMS="--all-databases --fast --silent"
MYCHECK_RCPT="${MYCHECK_RCPT:-root}"
## Checking for corrupt, not cleanly closed (only for MyISAM and Aria engines) and upgrade needing tables.
# The following commands should be run when the server is up but in background
# where they do not block the server start and in one shell instance so that
# they run sequentially. They are supposed not to echo anything to stdout.
# If you want to disable the check for crashed tables comment
# "check_for_crashed_tables" out.
# (There may be no output to stdout inside the background process!)
# Need to ignore SIGHUP, as otherwise a SIGHUP can sometimes abort the upgrade
# process in the middle.
trap "" SIGHUP
(
upgrade_system_tables_if_necessary;
check_root_accounts;
check_for_crashed_tables;
) >&2 &
exit 0
And then chmod 755 /etc/mysql/debian-start
After that, voila:
sudo service mariadb restart
sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.5.8-MariaDB-1:10.5.8+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Given the steps you've tried so far, I'd recommend blowing away pretty much all of it to try to start over "clean":
sudo apt remove mariadb-server
sudo apt autoremove
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql
sudo rm -rf /usr/lib/mysql
Then reinstall mariadb-server and follow the steps above to create the correct files.

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.)

Missing Network function on LXD?

I am trying to configure the networking options for my lxd container but when I try the following command:
lxc network create testbr0
I get the following result:
root#Server02:/var/lib# lxc network create testbr0
Usage: lxc [options]
Checking the list of available commands, I dont see network as an option
Here are the available commands I see:
config, copy, delete, exec, file, finger, image, info, init, launch, list, monitor, move, pause, profile, publish, remote, restart, restore, snapshot, start, stop, version
I'm using Ubuntu 14.04
Any insights?
Thanks
I assume you are using lxd Version 2.0.11. There is no network command in this version.
If you want to use the network command you have to install lxd feature releases (LXD 2.x).
On Ubuntu 14.04 there is no ppa containing the lxd feature releases, so you have to install snap and use the snap package:
sudo apt update
# check if snap is installed, install it if not
if ! type snapctl >/dev/null; then sudo apt install -y snapd; fi
# install lxd
sudo snap install lxd
# wait for lxd startup
while ! echo -e "GET / HTTP/1.0\r\n" | sudo nc -U /var/snap/lxd/common/lxd/unix.socket > /dev/null; do sleep 1; done
# migrate from ppa to snap lxd
sudo /snap/bin/lxd.migrate
# 14.04 does not add the user to lxd group so we do it explicitly
sudo adduser $(id -un) lxd

Why SSH connection to docker container is not working?

So i have this Dockerfile:
FROM debian:squeeze
MAINTAINER Name < email : >
# Update the repository sources list
RUN apt-get update
# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 build-essential php5 mysql-server openssh-server libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur
# Enable apache mods.
RUN a2enmod php5
RUN a2enmod rewrite
# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
EXPOSE 80
# Copy site into place.
ADD www /var/www/site
# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
# start mysqld and apache
EXPOSE 3306
RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
EXPOSE 22
CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl -D FOREGROUND;/usr/sbin/sshd -D'
it builds up, no problem,MySQL and Apache start and work fine but the ssh won't work and i don't know why. openssh-server is installed.
i tried starting it up like this:
#startup.sh file
#/bin/bash
sshd
+
ADD ./startup.sh /opt/startup.sh
ENTRYPOINT ["/opt/startup.sh"]
and many other,i'm stuck.
What am i doing wrong?
you are starting apache in the foreground, hence the apachectl process will never give back the hand to the shell that started it and thus the /usr/sbin/sshd -D will never be called (unless you kill apache).
The following instruction will start both mysql and apache in the background and then sshd in the foreground:
CMD bash -c ' (mysqld &); /usr/sbin/apache2ctl start;/usr/sbin/sshd -D'
While such a CMD statement is ok for tests I would advise using a different approach for running multiple processes in a single docker container:
supervisor
phusion/baseimage
Replace below lines of code in the docker file,
RUN mkdir /var/run/sshd
RUN echo 'root:123' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
Using these codes
RUN apt-get install -y openssh-server
RUN echo 'root:password' |chpasswd
RUN mkdir -p /var/run/sshd
this works for me.
Note: Use ssh only for debugging purpose, it is not a good practice at all.