How to install mysql on centos and set up remote access

How to install mysql on centos and set up remote access

1. Download the mysql repo source

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. Install the mysql-community-release-el7-5.noarch.rpm package

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

After installing this package, you will get two MySQL yum repo sources: /etc/yum.repos.d/mysql-community.repo and /etc/yum.repos.d/mysql-community-source.repo.

3. Install MySQL

$ sudo yum install mysql-server

Just follow the prompts to install it, but there is no password after the installation, you need to reset the password

4. Reset mysql password

$ mysql -u root

When logging in, the following error may be reported: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2). The reason is the access permission problem of /var/lib/mysql. The following command changes the owner of /var/lib/mysql to the current user:

$ sudo chown -R root:root /var/lib/mysql

Restart mysql service

$ service mysqld restart

Next, log in to reset your password:

$ mysql -u root //Press Enter directly to enter the mysql consolemysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

For security reasons, Mysql only allows users to log in locally by default. However, in this case, users still need to connect remotely. Therefore, in order to enable remote connection, the following operations need to be performed:

1. Allow the root user to log in remotely from anywhere and have any operation permissions for all libraries. The specific operations are as follows:

Log in to mysql as root user on this machine:
mysql -u root -p "youpassword" 
To perform authorization operations:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
Reload the authorization table:
FLUSH PRIVILEGES;
Exit the mysql database:
exit

2. Allow the root user to log in remotely from a specific IP address and have any operation permissions for all libraries. The specific operations are as follows:

Log in to mysql as root user on this machine:
mysql -u root -p "youpassword" 
To perform authorization operations:
GRANT ALL PRIVILEGES ON *.* TO root@"172.16.16.152" IDENTIFIED BY "youpassword" WITH GRANT OPTION;
Reload the authorization table:
FLUSH PRIVILEGES;
Exit the mysql database:
exit

3. Allow the root user to log in remotely from a specific IP address and have all library-specific operation permissions. The specific operations are as follows:

Log in to mysql as root user on this machine:
mysql -u root -p "youpassword" 
To perform authorization operations:
GRANT select,insert,update,delete ON *.* TO root@"172.16.16.152" IDENTIFIED BY "youpassword";
Reload the authorization table:
FLUSH PRIVILEGES;
Exit the mysql database:
exit

4. To delete user authorization, you need to use the REVOKE command. The specific command format is:

REVOKE privileges ON database[.table name] FROM user-name;
For a specific example, first log in to mysql locally:
mysql -u root -p "youpassword" 
To perform authorization operations:
GRANT select,insert,update,delete ON TEST-DB TO test-user@"172.16.16.152" IDENTIFIED BY "youpassword";
Then delete the authorization operation:
REVOKE all on TEST-DB from test-user;
****Note: This operation only clears the user's authorization permissions for TEST-DB, but the user "test-user" still exists.
Finally, clear the user from the user table:
DELETE FROM user WHERE user="test-user";
Reload the authorization table:
FLUSH PRIVILEGES;
Exit the mysql database:
exit

5. Detailed classification of MYSQL permissions:

Global management permissions: 
FILE: Read and write files on the MySQL server. 
PROCESS: Display or kill service threads belonging to other users. 
RELOAD: Reload access control lists, refresh logs, etc. 
SHUTDOWN: Shut down the MySQL service.
Database/table/column permissions: 
ALTER: Modify existing data tables (such as adding/deleting columns) and indexes. 
CREATE: Create a new database or table. 
DELETE: Deletes records from a table. 
DROP: Delete a table or database. 
INDEX: Create or delete an index. 
INSERT: Add records to the table. 
SELECT: Display/search records of a table. 
UPDATE: Modify existing records in the table.
Special permissions: 
ALL: Allows you to do anything (same as root). 
USAGE: Only login is allowed - nothing else is allowed.

Summarize

The above is the operation method of installing MySQL on CentOS and setting up remote access 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:
  • How to set mysql5.7 encoding set to utf8mb4
  • Detailed explanation of two methods for setting global variables and session variables in MySQL
  • Sharing the detailed process of setting up Mysql5.6 to allow external network access
  • How to set the character set for mysql under Docker
  • How to set default value for datetime type in MySQL
  • Detailed explanation of using Dockerfile to build MySQL image and implement data initialization and permission setting
  • MySQL log settings and viewing methods
  • How to install MySQL 5.7.17 and set the encoding to utf8 in Windows
  • How to install MySQL on CentOS 7 and set it to start automatically
  • MySQL max_allowed_packet setting

<<:  Detailed explanation of the usage of common Linux commands (Part 2) ———— Text editor commands vi/vim

>>:  Detailed explanation of this reference in React

Recommend

Sample code for seamless scrolling with flex layout

This article mainly introduces the sample code of...

Navicat for MySQL 15 Registration and Activation Detailed Tutorial

1. Download Navicat for MySQL 15 https://www.navi...

Tutorial on deploying the open source project Tcloud with Docker on CentOS8

1. Install Docker 1. I installed Centos7 in the v...

MySQL functional index optimization solution

When using MySQL, many developers often perform f...

Setting up a proxy server using nginx

Nginx can use its reverse proxy function to imple...

A simple tutorial on how to use the mysql log system

Table of contents Preface 1. Error log 2. Binary ...

Detailed steps for installing and configuring mysql 5.6.21

1. Overview MySQL version: 5.6.21 Download addres...

HTML Tutorial: Ordered Lists

<br />Original text: http://andymao.com/andy...

Detailed installation and configuration tutorial of PostgreSQL 11 under CentOS7

1. Official website address The official website ...

Detailed explanation of the adaptive adaptation problem of Vue mobile terminal

1. Create a project with vue ui 2. Select basic c...

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on th...

Detailed description of mysql replace into usage

The replace statement is generally similar to ins...

Docker binding fixed IP/cross-host container mutual access operation

Preface Previously, static IPs assigned using pip...