HUAWEI CLOUD cloud server evaluation|Deploy Mysql database in Docker environment

I. Introduction

1.1 Introduction to Yunyao Cloud Server L instance

Yunyao cloud server L instance is a new generation of lightweight application cloud server, specially designed for small and medium-sized enterprises and developers, providing out-of-the-box convenience. Yunyao cloud server L instances provide rich and strictly selected application images, which can deploy applications with one click, which greatly simplifies the process for customers to build e-commerce websites, web applications, small programs, learning environments, and various development and testing tasks in the cloud. process.

insert image description here

1.2 Introduction to Mysql database

MySQL is an open source relational database management system (RDBMS), which uses SQL (Structured Query Language) as its language, allowing users to operate and manage data through SQL statements. MySQL was developed by MySQL AB of Sweden and is now a product of Oracle Corporation. MySQL is one of the most popular open source relational database management systems, widely used in the development of web applications. MySQL is characterized by fast speed, high security, easy use and management, and good scalability. MySQL supports a variety of operating systems, including Linux, Windows, Mac OS, and more. The current latest stable version is MySQL 8.0.

2. Introduction to this practice

2.1 Introduction to this practice

1. This practice is a personal test and learning environment, which aims to quickly deploy applications. Please be cautious in the production environment;
2. This practice environment is Yunyao Cloud Server L instance, and the application image used is Portainer 2.18.4;
3. In Portainer Deploy Mysql database on the platform.

2.2 This environmental planning

server class application image Intranet IP address Docker version Portainer version MySQL version
Yunyao cloud server L instance Docker Visual Portainer 192.168.0.168 24.0.4 2.18.4 8.0

3. Purchase Yunyao Cloud Server L instance

3.1 Log in to HUAWEI CLOUD

Log in to your personal HUAWEI CLOUD account, enter Yunyao Cloud Server L instance in the search bar, press Enter to confirm, and enter the Yunyao Cloud Server L instance details page.

insert image description here
insert image description here

insert image description here

3.2 Purchase Yunyao Cloud Server L instance

On the Yunyao Cloud Server L instance details page, click Purchase.

insert image description here

Region: North China—Beijing 4;
Application Image: Docker Visualization-Portainer;
Instance Specifications: 2 Cores 2G/System Disk 40G/Peak Bandwidth 3Mbps/Traffic Package 400G;
Instance Name: You can customize it, edit it here as HECS-L-Portainer ;
Purchase duration: 1 month;

insert image description here

insert image description here

  • Check configuration, confirm purchase.

insert image description here

3.3 View Yunyao Cloud Server L instance status

Check the status of the purchased Yunyao Cloud Server L instance, which is in normal operation.

insert image description here

3.4 Reset server password

Click to remotely log in to Yunyao Cloud Server L instance

insert image description here

insert image description here

To reset the password, click the reset password option on the right, and identity verification is required. After selecting mobile phone verification, the password can be reset successfully.

insert image description here

insert image description here

4. Check the Docker environment

4.1 Check the elastic public IP address

  • Copy the elastic public IP address and use it when connecting to the server remotely.

insert image description here

4.2 Xshell connects to the server

In the Xshell tool, fill in the server’s elastic public network IP address, account and password information, and connect to the remote server with ssh.

insert image description here

insert image description here

insert image description here

4.3 Check Docker service status

Since the application image used by Yunyao Cloud Server L instance is Portainer, the Docker environment has been automatically deployed, and there is no need to reconfigure the Docker environment.

  • Check Docker version
root@hcss-ecs-f91c:~# docker -v
Docker version 24.0.4, build 3713ee1
  • Check Docker service status
root@hcss-ecs-f91c:~# systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-09-05 21:51:04 CST; 16h ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1061 (dockerd)
      Tasks: 88
     Memory: 519.8M
        CPU: 1min 956ms
     CGroup: /system.slice/docker.service

4. Download the mysql:8.0 image

Pull the mysql:8.0 image from docker hub.

root@hcss-ecs-f91c:~# docker pull  mysql:8.0
8.0: Pulling from library/mysql
b193354265ba: Pull complete
14a15c0bb358: Pull complete
02da291ad1e4: Pull complete
9a89a1d664ee: Pull complete
a24ae6513051: Pull complete
5110d0b8df84: Pull complete
71def905d921: Pull complete
c29c4f8eb3c1: Pull complete
769af171cdaa: Pull complete
c1a0ba6abbff: Pull complete
5e7e1ae11403: Pull complete
Digest: sha256:f0e71f077bb27fe17b1b9551f75d1b35ad4dfe3a33c82412acf19684790f3a30
Status: Downloaded newer image for mysql:8.0
docker.io/library/mysql:8.0

5. Deploy Mysql application

5.1 Create Mysql container

Use the docker-cli command to create a mysql container.

docker run -d --name mysql_01 --restart always -v /data/mysql/:/var/lib/mysql -p 3641:3306 -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=data mysql:8.0

insert image description here

5.2 Check the status of the Mysql container

Check the status of the mysql container to ensure that the container starts normally.

root@hcss-ecs-f91c:~# docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED          STATUS          PORTS                     NAMES
c5962b2ee9f3   mysql:8.0                       "docker-entrypoint.s…"   12 minutes ago   Up 12 minutes   33060/tcp, 0.0.0.0:3641->3306/tcp, :::3641->3306/tcp                     mysql_01

5.3 Check the container operation log

Check the mysql container running log.

insert image description here

6. Log in to the Mysql database locally

6.1 Enter the mysql container

Enter the mysql container

docker exec -it mysql_01 /bin/bash

6.2 Log in locally to connect to mysql

Log in locally to connect to the mysql database

bash-4.4# mysql -uroot -padmin
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

6.3 Set user name and password

  • New users
create user 'admin'@'%' identified WITH mysql_native_password BY 'admin';
  • Set user permissions
grant all on *.* to  'admin'@'%'    with GRANT OPTION;
flush privileges;

insert image description here

Seven, remote login Mysql database

7.1 Allow security group ports

In the security group configuration management of Yunyao Cloud Server L instance, allow port 3641 in the inbound direction.

insert image description here
insert image description here

7.2 Remote connection to mysql database

Remotely connect to the mysql database on the mysql client of other Linux servers, where -h is followed by the elastic public network IP address of the Yunyaoyun server L instance.

[root@server ~]# mysql -hxxxx -P 3641 -uadmin -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

insert image description here

7.3 Write data

  • create database
create database school;
  • View new database
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| data               |
| information_schema |
| mysql              |
| performance_schema |
| school             |
| sys                |
+--------------------+
6 rows in set (0.00 sec)
  • Enter the school database
mysql> use school;
Database changed
  • Create a new data table and create an empty data table.
 CREATE TABLE IF NOT EXISTS `student`(
     `id` INT UNSIGNED AUTO_INCREMENT,
      `name` VARCHAR(100) NOT NULL,
    `gender` TINYINT NOT NULL,
     `age` INT UNSIGNED,
    `class` INT UNSIGNED,
      `score` INT UNSIGNED,
      PRIMARY KEY ( `id` )
    )ENGINE=InnoDB DEFAULT CHARSET=utf8;

insert image description here

  • Write data to the data table student.
 insert into student ( name, gender, age, class,  score ) values ( "李一成", "1", "16", "1", "78" );
 insert into student ( name, gender, age, class,  score ) values ( "王萌", "0", "15", "2", "88" );
 insert into student ( name, gender, age, class,  score ) values ( "张磊", "1", "16", "4", "98" );

insert image description here

  • Query data table content
mysql> select * from student;
+----+-----------+--------+------+-------+-------+
| id | name      | gender | age  | class | score |
+----+-----------+--------+------+-------+-------+
|  1 | 李一成    |      1 |   16 |     1 |    78 |
|  2 | 王萌      |      0 |   15 |     2 |    88 |
|  3 | 张磊      |      1 |   16 |     4 |    98 |
+----+-----------+--------+------+-------+-------+
3 rows in set (0.03 sec)

7.4 phpMyAdmin tool remote connection database

Use the phpMyAdmin tool to remotely connect to the database, and you can query the contents of the data table normally.

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/jks212454/article/details/132713649