Install MySQL 5.7 on CentOS 7 using the MySQL Yum repository

1. Uninstall the built-in MariaDB dependency package

[root@localhost ~]# yum makecache fast

[root@localhost ~]# yum list installed mariadb\*

 

[root@localhost ~]# yum remove mariadb-libs.x86_64

 

2. Download the MySQL repository

Repository page https://dev.mysql.com/downloads/repo/yum/

[root@localhost ~]# yum install wget -y

 

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

 

[root@localhost ~]# yum install mysql80-community-release-el7-7.noarch.rpm -y

[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"

 

[root@localhost ~]# yum repolist all | grep mysql

[root@localhost ~]# yum install -y yum-utils

 

Close the repository configuration for MySQL8.0

[root@localhost ~]# yum-config-manager --disable mysql80-community

 

Open the repository configuration of MySQL5.7 

[root@localhost ~]# yum-config-manager --enable mysql57-community

[root@localhost ~]# yum repolist enabled | grep mysql

 

3. Install MySQL 5.7

[root@localhost ~]# yum install mysql-community-server -y

 

You can list all of the MySQL packages available in the MySQL Yum component repository for your platform with the command:

[root@localhost ~]# yum --disablerepo=\* --enablerepo='mysql*-community*' list available

 

4. Start the service and initialize the database

[root@localhost ~]# service mysqld start

 

[root@localhost ~]# service mysqld status

 

 Get the initial password of the database

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

Initialize the database

[root@localhost ~]# mysql_secure_installation

Enter the password just now 

[root@localhost ~]# mysql_secure_installation 

Securing the MySQL server deployment.

Enter password for user root: 

The existing password for the user account root has expired. Please set a new password.

New password: 

Re-enter new password: 
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@localhost ~]# 

[root@localhost ~]# mysql_secure_installation

Secure MySQL server deployments.

Enter root user password:

The root user password has expired. Processing steps Please set a new password.

New Password:

Re-enter the new password:

The 'validate_password' plugin is installed on the server.

The next steps will use the existing configuration to run

plug-in.

Use the existing root password.

Estimated strength of password: 100

Change root user password? (press y|y for yes, other keys for no): n

.. jump over.

By default, MySQL installations have an anonymous user,

Allow anyone to log in to MySQL without

User accounts created for them. this is just for

Test and make the installation smoother.

You should remove them before going to production

Delete anonymous user? (press y | y for yes, other keys for no): y

success.

Normally, only the root user should be allowed to

"localhost". This ensures that no one can guess

root password from the network.

Disable root user remote login? (press y|y for "yes", other keys for "no"): n

.. jump over.

By default, MySQL ships with a database named "test"

Anyone can access. This is also only for testing,

and should be removed before going into production

environment.

Delete the test database and access it? (press y | y for yes, other keys for no): y

- Delete test database...

success.

- Remove permissions on test database...

success.

Reloading the privilege table will ensure all changes

The provisions currently in place will take effect immediately.

Reload privilege table now? (press y | y for yes, other keys for no): y

success.

Completed!

root@localhost ~ #

Probably the English explanation is as above, and follow the prompts to enter y or n

Initialize the database complete

The default password policy enforcer requires passwords to contain at least one uppercase letter, one lowercase letter, one number, and one special character, and to have a total password length of at least 8 characters.

Restart the database service

[root@localhost ~]# service mysqld restart

[root@localhost ~]# service mysqld status

5. Test local login

[root@localhost ~]# mysql -u root -p

 

Notice:

Mysql is case-insensitive by default. MySQL’s case rules for database names, table names, column names, and aliases under Linux are as follows: 1) database names and table
names are strictly case-sensitive;
2) table aliases are strictly case-sensitive Case-sensitive;
3) Column names and column aliases are case-insensitive in all cases;
4) Variable names are also strictly case-sensitive; 

Check database version

mysql> status;

 

exit mysql

mysql> exit

 

6. Remote login is enabled and tested (you can choose to enable remote or not to enable remote) 

Log in to the database locally

View the access permissions of individual users in the database

mysql> select user,host from mysql.user;

 

From the above, we can observe that the access authority of the user root is localhost, which means that the root user only supports local access

Allow root remote
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'database root user password' WITH GRANT OPTION; *.
* means all tables in all libraries, 'root' user, '%' means remote 'localhost' means local

mysql> grant all privileges on *.* to 'root'@'%' identified by 'xxx' with grant option;

 

Refresh library table permissions

mysql> flush privileges;

View the access rights of each user in the database again

mysql> select user,host from mysql.user;

 

Test remote login

You can use the database connection tool or use the command connection on another server with MySQL installed

I choose the latter here

Before connecting, make sure that the remote connected MySQL server must release the database port

Check the services allowed by the firewall

[root@localhost ~]# firewall-cmd --list-all

Allow the MySQL service through the firewall permanently

[root@localhost ~]# firewall-cmd --permanent --add-service=mysql

 

reload firewalld rules

[root@localhost ~]# firewall-cmd --reload

 

Database remote login mysql -h database server host address -P database port -u database user -p

[root@localhost ~]# mysql -h 10.0.0.4 -P 3306 -u root -p

 

 

Guess you like

Origin blog.csdn.net/wxqndm/article/details/127960350