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

When should a website place ads?

I recently discussed "advertising" with...

Detailed explanation of three ways to import CSS files

There are three ways to introduce CSS: inline sty...

MySQL optimization strategy (recommended)

In summary: 1. Consider performance when designin...

Linux command line operation Baidu cloud upload and download files

Table of contents 0. Background 1. Installation 2...

How to configure Nginx domain name rewriting and wildcard domain name resolution

This article introduces how to configure Nginx to...

Common failures and reasons for mysql connection failure

=================================================...

JS ES6 asynchronous solution

Table of contents Initially using the callback fu...

Import csv file into mysql using navicat

This article shares the specific code for importi...

Vue implements online preview of PDF files (using pdf.js/iframe/embed)

Preface I am currently working on a high-quality ...

Sample code for implementing two-way authentication with Nginx+SSL

First create a directory cd /etc/nginx mkdir ssl ...

A detailed introduction to JavaScript execution mechanism

Table of contents 1. The concept of process and t...

MySQL free installation version configuration tutorial

This article shares the MySQL free installation c...