Install mysql on centos and set the operation method of remote access

  • 2021-09-20 21:47:02
  • OfStack

1. Download the repo source for mysql

$ 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 yum repo sources for mysql:/etc/yum. repos. d/mysql-community. repo,/etc/yum. repos. d/mysql-community-source. repo.

3. Install mysql


$ sudo yum install mysql-server

You can install it according to the prompt, but there is no password after the installation is completed, so you need to reset the password

4. Reset the mysql password


$ mysql -u root

It is possible to report such an error on login: ERROR 2002 (HY000): Can 'ES50connect local MySQL server through socket'/var/lib/mysql/mysql. sock '(2) due to access issues/var/lib/mysql. The following command changes the owner of/var/var to the current user:


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

Restart the mysql service


$ service mysqld restart

Next, log in and reset the password:


$ mysql -u root // Enter directly mysql Console 
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

Mysql For security purposes, users are only allowed to log in locally by default, but in this case, you still need to use users to connect remotely, so you need to do the following in order for them to be remote:

1. Allow root users to log in remotely from anywhere and have any operation rights of all libraries, as follows:


 Use it first on this machine root User login mysql : 
mysql -u root -p"youpassword" 
 Perform authorization operations: 
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
 Overload the authorization table: 
FLUSH PRIVILEGES;
 Quit mysql Database: 
exit

2. Allow root users to log in remotely on a specific IP and have any operation rights for all libraries, as follows:


 Use it first on this machine root User login mysql : 
mysql -u root -p"youpassword" 
 Perform authorization operations: 
GRANT ALL PRIVILEGES ON *.* TO root@"172.16.16.152" IDENTIFIED BY "youpassword" WITH GRANT OPTION;
 Overload the authorization table: 
FLUSH PRIVILEGES;
 Quit mysql Database: 
exit

3. Allow root users to log in remotely on a specific IP with all library-specific operation permissions as follows:


 Use it first on this machine root User login mysql : 
mysql -u root -p"youpassword" 
 Perform authorization operations: 
GRANT select , insert , update , delete ON *.* TO root@"172.16.16.152" IDENTIFIED BY "youpassword";
 Overload the authorization table: 
FLUSH PRIVILEGES;
 Quit mysql Database: 
exit

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


REVOKE privileges ON  Database [. Table name ] FROM user-name;
 For specific examples, log in to this machine first mysql:
mysql -u root -p"youpassword" 
 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 TEST-DB But this " test-user "This user still exists. 
 Finally, clear the user from the user table: 
DELETE FROM user WHERE user="test-user";
 Overload the authorization table: 
FLUSH PRIVILEGES;
 Quit mysql Database: 
exit

5. Detailed classification of MYSQL permissions:


$ sudo yum install mysql-server
0

Summarize

Above is this site to introduce you to install mysql on centos and set up remote access to the operation method, I hope to help you, if you have any questions welcome to leave me a message, this site will reply to you in time!


Related articles: