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

HTML table tag tutorial (21): row border color attribute BORDERCOLOR

To beautify the table, you can set different bord...

Use Visual Studio Code to connect to the MySql database and query

Visual Studio Code is a powerful text editor prod...

Detailed explanation of JavaScript onblur and onfocus events

In HTML pages, visual elements such as buttons an...

CSS uses calc() to obtain the current visible screen height

First, let's take a look at the relative leng...

Example code for implementing simple ListViews effect in html

HTML to achieve simple ListViews effect Result: c...

WeChat applet implements sorting function based on date and time

I recently took over a small program project, and...

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...

6 ways to view the port numbers occupied by Linux processes

For Linux system administrators, it is crucial to...

MySQL 8.0.19 installation and configuration tutorial under Windows 10

I will be learning MySQL next semester. I didn...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

Detailed explanation of Linux netfilter/iptables knowledge points

Netfilter Netfilter is a packet processing module...