This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

preface

  • Online music poke me ah!
  • Music blog source code online!
  • In the last two months, I did not write an article for a period of time, not because I was lazy, but because I had been working overtime for the project for a week. The project manager came off work early and said that the version could not be postponed.
  • To do a thing, the most sad is that you have worked very hard, without even a little complaint, just want to hear others praise to you, the heart may be enough, the most afraid that people will not appreciate, but come to say you this is not good, that is not good.
  • Of course, I will spend some time studying in the evening. After all, time is like milk.
  • The server I used to work in Shunde was Win, so MY server was always Win. When I changed my job to Guangzhou, the server was Linx, but I found that Linx was good. Now, the space is a hard problem for me, so I decided to migrate to Linx system.
  • The following step by step, take you into the whole process | Mysql.

One of the best things you’ll do this year: Book your girlfriend for 10 cents for a date (hard to book? No matter, money can really do as one pleases, a week or so about the dozen up).

demand

At present, music blog is deployed on Win7, and the main applications are:

  • The back-end have
    • Java As a third-party application, a Java image must be installed (šŸ‘ŒšŸ»).
    • Node as the main background, you need to install a Node image
  • The database is
    • If Java connects to Oracle, you need to install an Oracle image
    • Install Mysql image (āœ”ļø) to connect to Mysql
  • Front-end projects are deployed on Nginx and require an Nginx image
  • The lyrics service is also deployed on Node
  • The Node connects to Mysql, and the Mysql image needs to be installed
  • Java connects to Oracle, and an Oracle image needs to be installed
  • Music files are stored on Minio

Need to migrate the above application to Linx, damn!

A lot of companies don’t let you touch the server, so now you can look at it and follow me and record the whole process from nothing to nothing on Linux. This article is mainly written to still use Win server, ready to migrate Linux friends, you can practice migrating server to Linux, Linux has many advantages, the most visible is space, fast speed… In the process of migration, there will be a lot of pits waiting for you to solve, the demand above will write, this paper mainly explains Docker, Linux deployment of Mysql, other applications continue to update, please look forward to!

Docker install mysql and connect

1.1 Searching for a Mirror

docker search mysql
Copy the code

You can also go to the official website to view the image tag and select the version you want, otherwise the latest version will be downloaded.

1.2 Downloading an Image

For example, 1.1 Searching for a Mirror, you can specify the version you want, or the latest version if you do not specify the version.

Docker pull mysql: 5.7Copy the code

1.3 Creating a container using an Image and running it

So far I’m using the first one to run the image.

Docker run --name mysql5.7 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7Copy the code

Of course, you can also customize the configuration.

The default configuration file for MySQL(5.7.19) is /etc/mysql.my.cnf. To customize the configuration, you are advised to create a.cnf file in the /etc/mysql.conf. d directory. The newly created file can be named as long as the suffix is CNF. The configuration items in the new file can override the configuration items in /etc/mysql.my.cnf.

docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD = 123456 - d mysql: 5.7Copy the code

Parameters that

  • 3306-3306 – p:

    • Example Map port 3306 of a container to port 3306 of a host.
  • – e MYSQL_ROOT_PASSWORD = 123456:

    • Example Initialize the password of user root.
  • V $PWD/conf: / etc/mysql/conf. D:

    • Mount the conf directory in the current host directory to the /etc/mysql.conf. d directory of the container.
  • V $PWD/logs/logs:

    • Mount the logs directory under the current directory of the host to /logs of the container.
  • V $PWD/data/mysql_data: :

    • Mount the data directory in the current directory of the host to /mysql_data of the container.
  • – lower_case_table_names = 1:

    • Set the table name and parameter name to ignore case.
  • – v/etc/localtime: / etc/localtime: ro:

    • Set the time of the container to synchronize with the host.

1.4 Modification after Installation

šŸ… of course you don’t have to. See their own situation to decide to modify oh ~

Docker starts a case-sensitive Mysql.

1.4.1 Method 1: Connect to the database and modify the configuration file to be case-sensitive

Connect to MySQL: check the current MySQL case sensitive configuration.

show global variables like '%lower_case%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | lower_case_file_system  | ON | | lower_case_table_names |0     |
+------------------------+-------+
Copy the code

The lower_case_file_system parameter indicates whether the current system file is case sensitive and cannot be changed.

  • ON is case insensitive
  • OFF case sensitive

Enter the docker MySQL container, edit/etc/MySQL/MySQL. Conf., d/mysqld. CNF file, under the (mysqld) add the following:

[mysqld]
lower_case_table_names=1
Copy the code

Save, exit container;

Sudo docker restart MySQL

mysql> show global variables like '%lower_case%'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | lower_case_file_system  | OFF | | lower_case_table_names |1     |
+------------------------+-------+
2 rows in set (0.00 sec)
Copy the code

1.4.1 Method 2: Add case sensitive parameters when running an image

Docker run --name mysql57. -p 3306:3306 
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
--lower_case_table_names=1Docker run -p3306:3306 --name mysql 
-v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs
-v $PWD/data:/mysql_data 
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7 
--lower_case_table_names=1
Copy the code

Key commands: –lower_case_table_names=1 Sets the table name and parameter names to ignore case

My own startup test command is as follows:

docker run -p 3306:3306 --name mysql57. -v 
/Volumes/data/develop/mysql/5.7/logs:/var/log/mysql -v 
/Volumes/data/develop/mysql/5.7/data:/var/lib/mysql 
-e MYSQL_ROOT_PASSWORD=password -e TZ='Asia/Shanghai' 
-d mysql:5.7 --lower_case_table_names=1
Copy the code

Parameter Description:

  • Password Changes the password to its own password

  • –restart=always: automatically restarts

If you need to define your own configuration file is adding – v/Volumes/data/develop/mysql/conf/my CNF hosting files; /etc/mysql.my. CNF Directory file in the docker container.

After the docker installation is successful, you can use the following command:

[root@chtest ~]# docker exec -it mysql bash
Copy the code

Enter docker container and modify mysql access authorization.

root@da55138960a4:/# mysql -h localhost  -uroot  

mysql> grant all privileges on *.* to root@"%" identified by "chbigdata" with grant option;

Query OK, 0 rows affected, 1 warning (0.00 sec)
Copy the code
mysql> flush privileges;Ā 

Query OK, 0 rows affected (0.00 sec)
Copy the code

1.5 Navicat for mysql Failed to connect to mysql

Navicat for mysql: Client does not support authentication protocol requested by server

šŸ…, of course, is not related to the above operation of the case-sensitive database, because the mysql installation does not have the configuration permission.

Solution:

Enter the container:

docker exec -it 62349aa31687 /bin/bash
Copy the code

Enter the mysql:

mysql -uroot -p
Copy the code

Authorization:

GRANTĀ ALLĀ ONĀ *.*Ā TOĀ 'root'@The '%';
Copy the code

Refresh permission:

flush privileges;
Copy the code

Update encryption rules:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Copy the code

Change the password of user root:

ALTER USER 'root'@The '%' IDENTIFIED WITH mysql_native_password BY '123456';
Copy the code

Refresh permission:

flush privileges;
Copy the code

Mysql > install mysql

In Linux, we use yum to install mysql.

2.1 Installing Yum on Linux

yun install -y telnet
Copy the code

2.2 Check whether mysql is installed in the system

Yum list installed mysql * RPM - qa | grep mysql *Copy the code

2.3 Checking whether the installation package is available

yum list mysql*
Copy the code

2.4 Installing the mysql Client

yum install mysql
Copy the code

2.5 Installing the mysql Server

yum install mysql-server

yum install mysql-devel
Copy the code

2.6 Adding the default character set to the /etc/my. CNF file

vim /etc/my.cnf
Copy the code

2.7 Starting or Stopping the mysql Service

Mysql /mysqld /mysqld /mysqld /mysqld /mysqld /mysqldCopy the code

2.8 Enabling the mysql service upon Startup

chkconfig --add mysqld
Copy the code

2.9 Creating the root user The password is 123456

Mysqladmin - u root password123456
Copy the code

2.10 connect the mysql

Mysql -u root -p -- Enter the password123456
Copy the code

2.11 Setting the Remote Access Permission

use mysql;

GRANT ALL PRIVILEGES ON *.* TO "admin"@"%"IDENTIFIED BY "admin"WITH GRANT OPTION; -- The first admin is the user name and the second admin is the password. % indicates that all computers can link to Flush Privileges. - The setting takes effect immediatelyCopy the code

SELECT DISTINCT CONCAT('User:'' ',user,' 'The '@'' ',host,' ''; ') AS query FROM mysql.user; exit; Exit the mysql serviceCopy the code
vi /etc/my.cnf


[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
default-character-set=utf8
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0Bind-address =0.0. 0. 0[mysqLD_safe] log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Copy the code
[root@localhost~]# service mysqld start -- restart mysql server [root@localhost~]# mysql -u root -pselect version(a); Mysql > show global variables like'port'; - check the port number + -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- + | Variable_name Value | | + -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- + | port |3306  |
+---------------+-------+
1 row in set (0.00 sec)
Copy the code

2.12 Using Navcat to Connect to mysql

Mysql > uninstall mysql

// Uninstall using RPM packagesCheck the package name: RPM - qa | grep -i mysql delete command: RPM -e -- nodeps package name// Yum installation mode download
1.Check the installed mysql command: RPM - qa | grep -i mysql2.Yum remove mysql-community-server-5.636.-2.El7. X86_64 check mysql other dependencies: RPM - qa | grep -i mysql// Unload dependencies
yum remove mysql-libs
yum remove mysql-server
yum remove perl-DBD-MySQL
yum remove mysql
Copy the code

The last

We have completed requirement 2: Mysql has been migrated to Docker for Linux as the database needed for Node connection.

We love project-driven learning, don’t we?

I, too, use my personal project – online music to drive me to learn Linux system, Docker, Java, Nginx and other front-end knowledge that may not be accessible. I think this may be the “breadth” of management.

See you later on Nginx

Related literature

Install mysql and connect using Docker

Install mysql with yum

Mysql > uninstall mysql

Docker install MySQL 5.7

In the past to recommend

Typora drag image generated online | Gitee figure bed

Multi-picture detailed explanation, one time to understand the prototype chain (ten thousand words)

Vue-cli3 builds the component library

Vue implements dynamic routing (and the interviewer blows project highlights)

Axios manipulation in a project you didn’t know about (Core principles of handwriting, compatibility)

VuePress builds project component documentation

Vue-typescript-admin-template background management system

The original link

Juejin. Cn/post / 702207…