Centos7 install mysql

MySQL installation

1.1.1 DownloadwgetCommand

yum -y install wget

Unable to install wget:

https://blog.csdn.net/YellowShite/article/details/115507120

1.1.2 Download the mysql installation package online

wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

1.1.3 Install MySQL

rpm -ivh mysql57-community-release-el7-8.noarch.rpm

1.1.4 Install mysql service

  • First enter the cd /etc/yum.repos.d/ directory.

cd /etc/yum.repos.d/

  • Install the MySQL service (this process may be a bit slow)

yum -y install mysql-server

rpm –import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

yum install mysql-server

1.1.5 Start MySQL

systemctl start mysqld

1.2 Modify MySQL temporary password

After MySQL is successfully installed, there will be a temporary password. We can use the grep command to view the temporary password. First log in to MySQL, and then change the MySQL password.

1.2.1 Get MySQL temporary password

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

1.2.2 Use a temporary password to log in first

mysql -uroot -p

When using the centos7 system, sometimes the error “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)” appears after entering the mysql database and entering the password and pressing Enter. So what should be done? This article www.appjzw.com briefly explains the solution.

Baidu directly cancels myaql password

  1. 1 Stop the MySQL service, the command is as follows
service mysqld stop
  1. 2. Modify the my.cnf configuration file in the MySQL installation directory to skip the permission check when logging in. The file is located in etc/my.cnf. The command is as follows :
    cd /etc/
    vi my.cnf
  2. After opening, #Add a line in the my.cnf file to skip the permission check when logging in:

Add under [mysqld]

skip_grant_tables
  1. 4 Start the MySQL service and log in to MySQL. You will be asked to enter a password. Enter any character and press Enter to enter MySQL. The command is as follows:
service mysqld start
  1. 5 The login mysql command is as follows:
mysql -u root -p

The solution is: Open /etc/my.cnf, and then add the following code below [mysqld]:

 plugin-load-add=validate_password.so

MySQL: ERROR 1193?(HY000):?Unknown system variable?…

1.2.3 Change the password verification strength of MySQL to low risk

set global validate_password_policy=LOW;

1.2.4 Modify the password length of MySQL

set global validate_password_length=5;

1.2.5 Modify MySQL password

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘admin’;

3. Execute first:

flush privileges;

4. Execute the password change command again, and it’s OK:

1.3 Allow remote access

1.3.1 First, turn off the Cenots firewall

First check the firewall status systemctl status firewalld

Then turn off the firewall

The firewall is turned off when the system is powered on systemctl stop firewalld (the firewall is turned off for this service)

After the server restarts, the firewall is disabled systemctl disable firewalld (disables the firewall service)

1.3.2 Modify MySQL to allow anyone to connect

1) First log in to MySQL

mysql -uroot -padmin
  1. Switch to mysql data
use mysql;
  1. View user table
select Host,User from user;

It was found that the root user is only allowed to log in to the localhost host.

  1. Modify to allow access from any address
update user set Host='%' where User='root';
  1. Refresh permissions
flush privileges;

1.3.3 Test using Navicat connection tool

1. Display the database list in the current database server:

mysql> SHOW DATABASES;

2. Create a database:

mysql> CREATE DATABASE library name;

mysql> CREATE DATABASE IF NOT EXISTS my_db default charset utf8 COLLATE utf8_general_ci;

3. Create a data table:

mysql> USE library name;

mysql> CREATE TABLE table name (field name VARCHAR(20), field name CHAR(1));

4. Delete the database:

mysql> DROP DATABASE library name;

How to modify the MySQL database name

.1 First create a new library:

  1. create database new_db;

1. 2 Use mysqldump to export data: ?

mysqldump -uroot -p123456 --set-gtid-purged=OFF old_db > /tmp/old_db.sql
  1. When doing ordinary local backup and recovery, you can add
  2. –set-gtid-purged=OFF
  3. The function is that GTID information does not appear during backup

1.3 Import data into the new database:

mysql -uroot -p123456 new_db < /tmp/old_db.sql