Run the MySQL database and persist the data file using the Docker container

Source: Internet
Author: User
Tags docker run

1. Download MySQL image

# docker Pull MySQL

2. Start the MySQL container

# docker run-itd-v/data:/var/lib/mysql-p 33060:3306--name mysqldb MySQL Bash
Warning:ipv4 forwarding is disabled. Networking won't work.
25d047a99917c6420412f36e1d0e2e6af38fc86539b2184d1ea7e5a47b955011

3, here we found that starting the MySQL container appears warning, the exclusion of warning methods are as follows:

# vi/etc/sysctl.conf

Added: Net.ipv4.ip_forward = 1

Effective configuration:

# sysctl-p
Vm.max_map_count = 262144
Net.ipv4.ip_forward = 1

Restart Network Service:

# Service Network Restart
Restarting network (via Systemctl): [OK]

Start the MySQL container again and notice that the warning disappears:

# docker run-itd-v/data:/var/lib/mysql-p 33060:3306--name mysqldb MySQL Bash
Bbde59a2921981218441851d7527d22be3a0e37d3164fd1e07c4653d5dccc94d

Note: The-V,-p parameters are used in the command to start the MySQL container from above, and the meanings are explained as follows:

-V: Hanging on the Volume,mysql database for the boot container The default data directory is the/var/lib/mysql directory in the container, which is the container's own volume, and if the data Catalog volume is not configured for the MySQL container separately, Then we will find that the MySQL database is missing after restarting the MySQL container. To persist MySQL data, we added the-v/data:/var/lib/mysql parameter to the MySQL container when we started it, and attached the host's/data directory to the/var/lib/mysql of the container.

-P: Specify the MySQL container to the native port mapping, the container 3306 port map to the host's 33060 port, so that after setting up, we can access the MySQL database on the LAN.

4. Enter the MySQL container and start the MySQL service:

# Docker exec-it MySQLdb Bash
[Email protected]:/# service MySQL Status
[INFO] MySQL Community Server 5.7.21 is not running.
[Email protected]:/# service MySQL start
No directory, logging in with home=/
..
[INFO] MySQL Community Server 5.7.21 is started.

5. Log in to MySQL database for basic configuration:

[Email protected]:/# mysql-uroot
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 3
Server version:5.7.21 MySQL Community Server (GPL)

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

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

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

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| Chavin |
| MySQL |
| Performance_schema |
| SYS |
+--------------------+
5 rows in Set (0.00 sec)

Mysql> Grant all privileges on * * to [e-mail protected] '% ' identified by ' MySQL ';
Query OK, 0 rows affected, 1 Warning (0.00 sec)

At this point, the Docker container-initiated MySQL database can be accessed within the LAN.

# mysql-uroot-pmysql-h192.168.177.129-p33060

Run the MySQL database and persist the data file using the Docker container

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.