Docker installs the latest version of Mysql (Mysql8.0)

Keywords: Docker MySQL yum SELinux

Docker installs the latest version of Mysql (Mysql8.0)

Docker environment configuration

1. Enter the following command to check whether the server has docker installed. If not, command not found will be replied

// View docker version
docker -v

2. Next, install docker. First install the software installation package. complete! Appears, indicating that the installation is successful!

// Software installation package installation
yum install -y yum-utils  device-mapper-persistent-data lvm2


3. Add yum source

// Add yum source
yum-config-manager \
--add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

4. View the version that this server can install

// View the version that this server can install
yum list docker-ce --showduplicates | sort -r

5. Install the corresponding version. If you don't know which one to install, execute the following command to install the latest version!

// Install the latest version
yum install docker-ce -y

6. Start docker and set docker to start

// Start docker
systemctl start docker
//Set docker startup
systemctl enable docker 

7. View the version information of docker after installation

// View docker version
docker -v
//View the specific version information of docker
docker version 

Mysql8.0 configuration

1. View mysql image

// View mysql version
docker search mysql

2. Install mysql directly, because the default installation is the latest version

// View mysql version
docker pull mysql

3. Set the account, password, mapped local host port number and docker port number of docker MySQL

// Set docker MySQL
docker run -it --rm --name ywjmysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql

Note: if mysql has been installed on your server (port 3306 is occupied), then install docker mysql in docker (the default port is also 3306). If it is enabled, the following exception will occur, and the port number is occupied! It is recommended to stop the original mysql service or modify the port number of the docker mysql mapping

How can I change my preferences! I like to modify the port number of docker mysql mapping, because I have two mysql databases, ha ha!

// Set docker MySQL
docker run -it --rm --name ywjmysql -e MYSQL_ROOT_PASSWORD=123456 -p 3316:3306 -d mysql

4. Use the following command to view the running container in the docker image, and you can clearly see the mysql container you just installed

// View running containers
docker ps -a

5. Enter mysql container:

// Enter mysql container
docker exec -it ywjmysql bash 

6. Log in mysql in the container

// Log in mysql in the container
mysql -uroot -p123456

7. View user information

// host% means unlimited IP localhost means local use    
select host,user,plugin,authentication_string from mysql.user;
//If plugin is not MySQL native password, the password needs to be modified
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES; 


8. After setting, you can exit;

//Quit mysql
mysql>exit;   

9. other

//Exit container and close
ctrl+d  
//View no
 docker ps 
//Exit the container without closing it,
ctrl+p+q 
//Quit mysql
docker ps Check out

Note:

Note 1

At present, the update iteration speed of docker container is also very fast. Some small partners still use the very old version of docker. If you want to upgrade to the latest version, you can try the following command:

// Stop docker service
systemctl stop docker
//View current version
rpm -qa | grep docker
// Uninstall package
yum erase docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce
//Uninstall related profiles
find /etc/systemd -name '*docker*' -exec rm -f {} \;

find /etc/systemd -name '*docker*' -exec rm -f {} \;

find /lib/systemd -name '*docker*' -exec rm -f {} \;

rm -rf /var/lib/docker   

rm -rf /var/run/docker  

After executing the above command, check whether it is command not found by executing the docker-v command!
If yes, you can install the latest version of docker after uninstalling and installing docker at the beginning of this article!
If it does not appear, it means that docker is not completely uninstalled!

Note 2

It is estimated that some small partners still fail to connect to docker mysql. Maybe your port is blocked by the server. Log in to the console and release the port!!



Last

So far, I have installed two MySQL servers, one is mysql5.7 and the other is mysql8.0. You can use whatever you want, ha ha!


Congratulations, docker MySQL has been built successfully!

If you think the writing is good, please click below to give a reward, thank you!!

Original: product R & D department - Yao Weijie
Original and high-quality products
Published 8 original articles, won praise 4, visited 213
Private letter follow

Posted by HiddenS3crets on Sat, 11 Jan 2020 00:27:57 -0800