MySql installation and configuration process under Centos7, simple direct installation version

Steps

1. Check whether Linux has installed MySql

PS: Those who have already installed can directly ignore this step

1. Method 1:

Order:

rpm -qa | grep mysql

When it has been installed, the following results will appear: the displayed installation package is as follows.
insert image description here
If it is not installed:
insert image description here
2. Method 2:

Order:

yum list installed | grep mysql

When installed, it will display as follows:
insert image description here

2. Clear MySQL (for reinstallation)

Note: This step is applicable to users whose mysql installation is incomplete and needs to be reinstalled. Other users can skip to Section 3 for reading.

1. Delete MySQL and its dependencies

1), check the dependency package

Note: The mariadb dependency package needs to be deleted under centos7. This command checks the existence of the mariadb dependency package.

rpm -qa | grep mariadb

This machine is not installed:
insert image description here
2), perform deletion

Delete method one:

  • Command 1: General deletion, if it prompts that there are dependent packages, it cannot be deleted
  • bashrpm -e mysql
  • Command 2: Forcefully delete, including various dependent packages
  • rpm -e --nodeps mysql57-community-release

Delete method two:

yum remove mysql-*
  • The deletion is completed as follows:
    insert image description here
2. Query legacy directories

The operation is as follows:

# whereis mysql

# mysql : /usr/lib64/mysql

# ls /etc/my.cnf //配置目录,一般情况用的很少

# ll /var/lib/mysql

The remaining directories after the query are as follows:
insert image description here

3. Delete the leftover directory

Execute if there are leftovers, and don’t execute if there are no leftovers

# rm -rf /etc/my.cnf 

# rm -rf /var/lib/mysql

The deletion is done as follows:
insert image description here

3. Start to install MySQL

We use a relatively simple way: use yumcommands to install.

Note: This method is only for the centos distribution version under linux, and other distribution versions such as Ubuntu and Debian may not support it.

1. Download and add the library
sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

insert image description here

2. Install the MySQL package

This process will automatically install the latest version (5.7), and a query will appear during the installation process, just type y all the way.

yum install mysql-community-server

Installation process:
insert image description here
Installation complete:
insert image description here

3. Set MySQL to start on boot
systemctl enable mysqld

systemctl daemon-reload

insert image description here

4. Start MySQL

Start mysql:

systemctl start mysqld

systemctl status mysqld

View mysql status:
insert image description here

5. Modify the MySQL password

When starting mysql for the first time, a temporary password is generated by default.

1), view the generated temporary password:tkjv%U%zR0a-

sudo grep 'temporary password' /var/log/mysqld.log

insert image description here
2), improve mysql security

sudo mysql_secure_installation

This process needs to enter a temporary password: tkjv%U%zR0a-.

After entering, you will be asked to enter a new password. The new password must contain at least 8 characters and contain at least one uppercase letter, one lowercase letter, one number and one special character.

The modification is completed as follows:
insert image description here
Type y directly for subsequent operations to improve security. After all operations are completed as follows:
insert image description here

6. Login to MySQL

Log in to mysql as root:mysql -u root -p

Connect as follows:
insert image description here
insert image description here

Fourth, set up MySQL remote login

1. Log in to MySQL and use the mysql library

Continue to step three. Next use the mysql library

use mysql

insert image description here

2. Grant permission to any IP address
grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;

insert image description here

3. Refresh permissions
flush privileges;

insert image description here

4. Check whether the modification takes effect
select host,user from user;

insert image description here

5. Tool connection test

Connection test: OK

Note: I set the hostname on the windows machine, and I can directly use the hostname for connection testing

insert image description here

V. Summary

The installation process is relatively simple, saving some cumbersome steps. I wrote a summary for myself, and I hope it can bring some help to everyone.

If you find any problems during the reading process, please comment or private message~

If readers think it’s not bad, move your cute little hands, one button and three links~~

Guess you like

Origin blog.csdn.net/qq_44281591/article/details/117935147