The environment
Mysql mysql80-community-release-el8-1.noarch.rpm mysql mysql80-community-release-el8-1.noarch.rpmCopy the code
Docker environment construction
download
Download and install it from www.docker.com/
Virtualization Settings
You can check whether virtualization is enabled in the task manager
Note: If virtualization is not enabled, log in to the BOIS to enable CPU virtualization (the specific operation varies with the mainboard).
Install centos
Search for and pull up a centos image
Docker pull centos Pulls an image
Run the mirror
Docker runit image encoding (enter the first three digits here)
Note: The default installation and image pulling environment of Docker is disk C. If you want to change, you can use soft link to link files to disk D mklink/J. docker d :.docker
The mysql environment is set up
If necessary, you can use the following command to check whether mysql has been installed
RPM - qa | grep mysql query whether install mysql RPM -e (mysql/delete mode RPM -e -- nodeps mysql / / strong delete mode, if you are using the above command to remove, prompt rely on other documents, You can use this command to forcibly delete itCopy the code
Yum -y install wget yum -y install wget
Download and install
Download address is: dev.mysql.com/downloads/r…
I installed Centos8, so let’s copy mysql80-community-release-el8-1.noarch. RPM
Then use the following command to install
wget http://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm rpm -ivh Mysql80-community-release-el8-1.noarch. RPM yum update yum install mysql80-community-release-el8-1.noarch. RPM yum update yum install mysql80-server install chown mysql:mysql -r /var/lib/mysql Mysqld --initialize Initialize mysql systemctl start mysqld start systemctl status mysqld Check the mysql running statusCopy the code
The installation result is as follows
Pay attention to the point
Systemctl introduction
Two methods of managing Linux services Service and systemctl Systemd is the latest Linux system initialization (init). It is used to speed up the system startup by starting as few processes as possible and concurrently starting as many processes as possible. The systemd process management command is systemctlCopy the code
The first use of the system is not required by the installation of systemctl
Yum install systemd -yCopy the code
I cannot run systemctl directly due to the problem of installing the centos version. I need to exit the image (remember docker commit save the image changes).
Use docker run-ITd --privileged -P 127.0.0.1:8001:80 -p 127.0.0.1:3306:3306 -p 127.0.0.1:8848-8848 1cf Run/usr/sbin/init containers - ring: all get root root - p is the interface mapping, later used, can let the docker port mapped to our local docker exec - coding/bin/bash it container into the containerCopy the code
Systemctl start mysqld = mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
Copy the code
Run mysqld.service systemctl status mysqlD. service
Enter the cat/var/log/mysql/mysqld. Log to check the mysql run log can be found
The innodb_system data file 'ibdata1' must be writable
Copy the code
Error: chmod -r 777 /var/lib/mysql: error: chmod -r 777 /var/lib/mysql
And then it starts successfully
Use mysqladmin –version to check the mysql version
Mysql -u root -p mysql -u root -p mysql -u root -p mysql -u root -p mysql -u root -p mysql -u root -p
Access denied for user 'root'@'localhost' (using password: YESCopy the code
To query data, you can add skip-grant-tables to your mysql configuration
The default configuration of mysql version I downloaded is not my.cnf, but mysql-server. CNF in my.cnf.d folder
Navicat connects to the database
use
show global variables like 'port'; Viewing port NumbersCopy the code
The port number is found to be 0 because port number configuration is not enabled
show variables like 'skip_networking'; Check whether the network port is configuredCopy the code
After querying relevant information, I found that skip-networking needs to be commented out to enable port configuration, which is not found in the configuration file. Then I found that skip-networking and skip-grant-tables need to be commented out at the same time to avoid secret login, because I don’t know the mysql password now. Therefore, you need to change the password of mysql root
Changing the Root Password
Log in to mysql in secret free mode and log in to the mysql database (use mysql). Run the following command to change the password
Update user set password= password (" your password ") where user = 'root'; Update user set authentication_string=' your password 'where user='root'; Alter user 'root'@'localhost' IDENTIFIED BY '123456' alter user 'root'@'localhost' IDENTIFIED BY '123456'; # Set password flush PRIVILEGES; The refreshCopy the code
Exit, comment out skip_networking and skip-grant-tables, re-log in mysql with the password we changed, and you can find the port number is 3306. Previously, we mapped 3306 to our local port 3306 when running Docker. Navicat connects to the database successfully. Procedure
The end of the
Note:
Update user set host =' %' where user ='root'; Select 'host' from user where user='root';Copy the code