CentOS7.x uninstall and install MySQL5.7 operation process and encoding format modification method

CentOS7.x uninstall and install MySQL5.7 operation process and encoding format modification method

1. Uninstalling MySQL 5.7

1.1查看yum是否安裝過mysql

cd

yum list installed mysql*

If or displays a list, it means that there is MySQL in the system.

As shown above, I have installed mysql, a total of 4 items

1.2yum uninstall mysql

Uninstall all the names that appear in the list

yum remove mysql-community-*

rm -rf /var/lib/mysql 刪除mysql的lib

rm /etc/my.cnf 刪除配置文件my.cnf

You can use the wildcard * to represent all

A confirmation dialog will pop up halfway, just select y

1.3. Delete other related files

Delete related configuration files

After uninstallation is complete, use View again

yum list installed mysql*

At this point, no relevant files are found, indicating successful uninstallation

View the remaining relevant files.

whereis mysql

Found that there is still a /usr/share/mysql that has not been deleted, continue to delete the file

View other configurations

systemctl list-unit-files | grep mysql

2. Install MySQL 5.7

1. Download the MySQL file

Domestic MySQL 5.7 mirror address

http://mirrors.163.com/mysql/Downloads/MySQL-5.7/

I chose 5.7.26-1.el7

2. Install MySQL

After decompression, I put it in the /OPT/MySQL folder

To install the mysql-server service, you only need to install the following five packages, and use rpm -ivh to install them (install in order, the later services depend on the previous services)

If an error occurs during the installation of clinet, as follows:

Cause: This is caused by yum installing an old version of GPG keys

Solution: Add --force --nodeps at the end

3. Check whether the installation is successful

#mysql --version

As shown in the figure above, 5.7.26 has been successfully installed

4. Initialize and generate an initial random password

# mysqld --initialize #After initialization, a random password will be generated in /var/log/mysqld.log

cat /var/log/mysqld.log View random password

In the last line you can see the default random password for the root user, which you will use when you log in later.

5. Modify the user and group of the MySQL database directory, and then start the MySQL database

If you do not modify the group attributes, MySQL will not start and will report an error.

6. Set the startup to start automatically

systemctl enable mysqld.service

7. Enter the MySQL database

The password used here is the initial password generated during initialization just now

8. Change the root password

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; 

9. Modify access permissions

Purpose: Any host connects to the MySQL server with user root and password 123456

10. Modify the character set

Since we are using a Chinese system and the default character set of MYSQL is latin1, garbled characters may appear easily, so we need to modify the character set encoding method.

After entering mysql, you will find

show variables like '%char%';

The current character set encoding method is as follows. In order to avoid garbled characters, the character set statistics need to be changed to utf8

Enter /etc/my.cnf file

Add these items

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character_set_server = utf8
collation_server = utf8_general_ci

Note the difference between _ and - here

After restarting the mysql service, enter mysql to view the code as follows

Please note that changing the character set will only take effect on the subsequent database, and will not be effective for the existing database. Therefore, it is recommended to change the encoding method as soon as possible after installing MYSQL.

The default path when installing MySQL with RPM

Data files: /var/lib/mysql/

Configuration file template: /usr/share/mysql mysql

Client tool directory: /usr/bin

Log directory: /var/log/pid

sock file: in the /var/lib/mysql/ directory

Generally, the configuration files are placed in /etc

Summarize

The above is the operation process of uninstalling and installing MySQL5.7 on CentOS7.x and the method of modifying the encoding format introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time!

You may also be interested in:
  • Linux CentOS 6.5 Uninstall, tar and install MySQL tutorial
  • How to completely uninstall mysql under CentOS
  • Several methods to completely uninstall MySQL under CentOS
  • How to uninstall MySQL 5.7 on CentOS7

<<:  In-depth explanation of Set and WeakSet collections in ES6

>>:  Installation and verification of pytorch in linux or windows environment (solving runtimeerror problem)

Recommend

Several ways to implement inheritance in JavaScript

Table of contents Structural inheritance (impleme...

vue+el-upload realizes dynamic upload of multiple files

vue+el-upload multiple files dynamic upload, for ...

Workerman writes the example code of mysql connection pool

First of all, you need to understand why you use ...

Discussion on the numerical limit of the ol element in the html document

Generally speaking, it is unlikely that you will ...

JavaScript closure details

Table of contents 1. What is a closure? 2. The ro...

HTML basics summary recommendation (paragraph)

HTML Paragraph Paragraphs are defined by the <...

Linux Disk Quota Management Graphical Example

Disk quota is the storage limit of a specified di...

Install Apple Mac OS X in VMWare12 Graphic Tutorial

1. Introduction: Because my friend wanted to lear...

Docker starts in Exited state

After docker run, the status is always Exited Sol...

Small problem with the spacing between label and input in Google Browser

Code first, then text Copy code The code is as fol...

Jenkins packaging microservices to build Docker images and run them

Table of contents Environment Preparation start 1...

Detailed introduction to the MySQL installation tutorial under Windows

Table of contents 1. Some concepts you need to un...

Mysql queries the transactions being executed and how to wait for locks

Use navicat to test and learn: First use set auto...