[Fail]: Starting MySQL in my Ubuntu docker - mysql

FROM ubuntu
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y mysql-server && \
apt-get install -y mysql-client
Then, I started a container, and ran:
/etc/init.d/mysql restart
Unfortunately, it didn't work:
root#5e37c0985d07:/opt# /etc/init.d/mysql restart * Stopping MySQL
database server mysqld
[ OK ]
* Starting MySQL database server mysqld
No directory, logging in with HOME=/
[fail]
Please note No directory, logging in with HOME in the error message.

Try usermod -d /var/lib/mysql mysql and then /etc/init.d/mysql restart

Try First to create an empty directory "mysql" at the host machine and then run the container with this directory path bind to the container directory path.
Ex:
docker run -i -t -p "3306:3306" -v ${PWD}/mysql:/var/lib/mysql "docker-image"

Related

How to install mysql-server in a Dockerfile?

I have a complex Dockerfile which install much more than just mysql-server so I cannot start from an existing mysql container.
When removing all the extra-stuff I get this Dockerfile
FROM ubuntu:latest
ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_ROOT_USER=root
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y mysql-server
RUN usermod -d /var/lib/mysql/ mysql
RUN service mysql start
Unfortunately, mysql does not want to start:
---> 57a66bd64c2c
Step 8/9 : RUN usermod -d /var/lib/mysql/ mysql
---> Running in 596df248c2e4
---> ee78442bcc56
Step 9/9 : RUN service mysql start
---> Running in 0d9e5803cf33
* Starting MySQL database server mysqld
...fail!
The command '/bin/sh -c service mysql start' returned a non-zero code: 1
What is my mistake?
Looks like you've removed the most important parts of your docker file. Here is the Official MySQL repo Docker file.
FROM oraclelinux:7-slim
ENV PACKAGE_URL https://repo.mysql.com/yum/mysql-8.0-community/docker/x86_64/mysql-community-server-minimal-8.0.2-0.1.dmr.el7.x86_64.rpm
# Install server
RUN rpmkeys --import http://repo.mysql.com/RPM-GPG-KEY-mysql \
&& yum install -y $PACKAGE_URL \
&& yum install -y libpwquality \
&& rm -rf /var/cache/yum/*
RUN mkdir /docker-entrypoint-initdb.d
VOLUME /var/lib/mysql
COPY docker-entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 3306 33060
CMD ["mysqld"]
You need to include a proper source with correct version to pull the image from.
and expose right ports, separate out volumes for MySQL to run. your container maybe failing due to any of this. I'd say remove the MySQL part out of your dockerfile and run the rest of the container.
Use the official mySQL image and install it in separate container. and then you can connect the Database with other apps.

docker run mysql just during one command

I am trying to install phpmyadmin into docker containers.
I am doing something like that :
Installing the MySQL-server and the phpmyadmin dependencies.
In one command:
Start MySQL-server.
Install phpmyadmin.
Stop MySQL-server.
This Dockerfile works perfectly on my computer but it is failing on hub.docker.com
Is anyone who how to execute MySQL command during the docker building process ?
RUN apt-get install -y -qq --no-install-recommends \
mysql-server-5.7 \
apache2 \
php7.0 \
php7.0-zip \
php7.0-bz2 \
php7.0-gd \
libapache2-mod-php7.0
# Fix MySQL home error
RUN usermod -d /var/lib/mysql mysql
RUN service mysql start && \
apt-get install -y -qq --no-install-recommends phpmyadmin && \
service mysql stop

MariaDB never starts within docker image

I'm creating a docker image with ubuntu trusty and MariaDB 5.5 but I can never get MariaDB to start unless I actually connect to the running VM.
Dockerfile:
FROM ubuntu:trusty
# Upgrade packages
RUN apt-get update && apt-get upgrade -y
# So we can add a repo to apt
RUN apt-get install -y software-properties-common
# Add MariaDB repo to aptitude
RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
RUN add-apt-repository 'deb http://mirror.jmu.edu/pub/mariadb/repo/5.5/ubuntu trusty main'
RUN apt-get update
# Install MariaDB
RUN DEBIAN_FRONTEND=noninteractive debconf-set-selections << 'mariadb-server-5.5 mysql-server/root_password password PASS'
RUN DEBIAN_FRONTEND=noninteractive debconf-set-selections << 'mariadb-server-5.5 mysql-server/root_password_again password PASS'
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y mariadb-server
# Start MariaDB
RUN service mysql start
# Configure MariaDB User permissions
RUN echo "CREATE USER 'ubuntu'#'localhost'" | mysql -u root
The command I'm running to create:
docker build -t ebth-com-trusty --file `pwd`/Dockerfile `pwd` --no-cache
The create command will always fail due to:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
But if I comment out the CREATE USER command, and then connect to the VM, I can connect to MariaDB just fine after running a manual service mysql start.
It is as if the RUN service mysql start just doesn't work, and I'm not sure how to debug this any further.
Every command in a Dockerfile is run in it's own container.
You can think of the process like:
new container is spun up using the previous image
the command is executed
the container is spun down
an image of that container is taken for the next command to run on
This means that the command RUN service mysql start will spin up a new container, start MariaDB, then shut down the container including shutting down MariaDB.
Instead try using CMD and ENTRYPOINT. You can think of them as setting the default executable, command and parameters executed once the container is spun up. However, the difference between the two is a bit more neuanced. Check out the docs: CMD and ENTRYPOINT
It would look something like this:
# Create default user
RUN service mysql start && \
echo "CREATE USER 'ubuntu'#'localhost'" | mysql -u root
# Start MariaDB
ENTRYPOINT ["/bin/bash"]
CMD ["service", "mysql", "start"]

mysql - installing or upgrading mysql 5.5 to 5.6 in Linux mint

Following error message getting while upgrading from Mysql 5.5 to 5.6.
The following packages have unmet dependencies:
mysql-client-5.6 : Depends: mysql-client-core-5.6 but it is not going to be installed
mysql-server-5.6 : Depends: mysql-server-core-5.6 (=
5.6.19-0ubuntu0.14.04.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I had the same problem which was solved after update and upgrade.
Try this, I hope this works for you:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install mysql-server-5.6
Installing MySQL 5.6 on Linux(debian based distro):
Uninstall any existing version of MySQL:
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-*
mysql-client-core-*
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
Automatically uninstall mysql:
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
Download version 5.5.51 from MySQL site
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
Add mysql user group:
sudo groupadd mysql
Add mysql (not the current user) to mysql user group:
sudo useradd -g mysql mysql
Extract mysql-5.6.*-linux2.6-x86_64.tar.gz to /usr/local:
cd /usr/local
sudo tar -xvf mysql-5.6.*-linux2.6-x86_64.tar.gz
Create mysql folder in /usr/local:
sudo mv mysql-5.6.*-linux2.6-x86_64 mysql
Set mysql directory owner and user group:
cd mysql
**sudo chown -R mysql:mysql * **
Install the required lib package:
sudo apt-get install libaio1
Execute mysql installation script:
sudo scripts/mysql_install_db --user=mysql
Set mysql directory owner from outside the mysql directory:
sudo chown -R root .
Set data directory owner from inside mysql directory:
sudo chown -R mysql data
Copy the mysql configuration file :
sudo cp support-files/my-medium.cnf /etc/my.cnf
Start mysql:
sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server
Initialize root user password:
sudo bin/mysqladmin -u root password 'test'
Start mysql server:
sudo /etc/init.d/mysql.server start
Stop mysql server
sudo /etc/init.d/mysql.server stop
Check status of mysql:
sudo /etc/init.d/mysql.server status
Enable myql on startup:
sudo update-rc.d -f mysql.server defaults
Add mysql path to the system:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
Now directly use the command below to start mysql
mysql -u root -p

Install MySQL 5.5 in Ubuntu 11.10

I have been downloaded the DEB package of mysql 5.5.23.
Install MySQL by the command as follows:
sudo dpkg -i mysql-5.5.23-debian6.0-x86_64.deb
The result said that installed successfully.
But when I type the command:
sudo service mysql start
Or
mysql
It shows me that "mysql: unrecognized service" or "mysql: command not found".
Besides, I can't find MySQL files in "/usr/include" or "/usr/bin"
Please help me. Thx.
Because MySQL 5.5.x is not packaged, in repositories only exist 5.1.x
This worked for me:
http://www.rebojo.com/debian-installing-mysql/
Why not a simple command :
sudo apt-get install mysql-server
MySQL Download URL
https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
Open the terminal and follow along:
Uninstall any existing version of MySQL
sudo rm /var/lib/mysql/ -R
Delete the MySQL profile
sudo rm /etc/mysql/ -R
Automatically uninstall mysql
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
Download version 5.5.51 from MySQL site
wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
Add mysql user group
sudo groupadd mysql
Add mysql (not the current user) to mysql user group
sudo useradd -g mysql mysql
Extract it
sudo tar -xvf mysql-5.5.56-linux-glibc2.5-x86_64.tar.gz
Move it to /usr/local
sudo mv mysql-5.5.56-linux-glibc2.5-x86_64 /usr/local/
Create mysql folder in /usr/local by moving the untarred folder
cd /usr/local
sudo mv mysql-5.5.49-linux2.6-x86_64 mysql
set MySql directory owner and user group
cd mysql
sudo chown -R mysql:mysql *
Install the required lib package (works with 5.6 as well)
sudo apt-get install libaio1
Execute mysql installation script
sudo scripts/mysql_install_db --user=mysql
Set mysql directory owner from outside the mysql directory
sudo chown -R root .
Set data directory owner from inside mysql directory
sudo chown -R mysql data
Copy the mysql configuration file
sudo cp support-files/my-medium.cnf /etc/my.cnf
Start mysql
sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server
Set root user password
sudo bin/mysqladmin -u root password '[your new password]'
Add mysql path to the system
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
Reboot!
Start mysql server
sudo /etc/init.d/mysql.server start
Stop mysql server
sudo /etc/init.d/mysql.server stop
Check status of mysql
sudo /etc/init.d/mysql.server status
Enable myql on startup
sudo update-rc.d -f mysql.server defaults
*Disable mysql on startup (Optional)
`sudo update-rc.d -f mysql.server remove`
REBOOT!
Now login using below command, start mysql server if it's not running already
mysql -u root -p