Install mysql on centos and set the operation method for remote access. centosmysql

Source: Internet
Author: User

Install mysql on centos and set the operation method for remote access. centosmysql

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 the yum repo source for both 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 as prompted, but there is no password after installation, and you need to reset the password

4. Reset the mysql password

$ mysql -u root

The following ERROR may be reported during logon: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql. sock '(2), because of/var/lib/mysql access permission issues. 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 on to reset the password:

$ Mysql-u root // directly press enter to enter the mysql console mysql> use mysql; mysql> update user set password = password ('000000') where user = 'root '; mysql> exit;

To ensure security, Mysql allows users to log on only locally by default. However, in this case, you still need to use the user for remote connection. Therefore, you need to perform the following operations remotely:

1. Allow the root user to log on Remotely Anywhere and have any operation permissions on all databases. The specific operations are as follows:

Log ON to mysql: mysql-u root-p "youpassword" as the root user ON the local machine for authorization: mysql> grant all privileges on *. * TO 'root' @ '%' identified by 'youpassword' with grant option; reload authorization table: flush privileges; exit mysql database: exit

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

Log ON to mysql: mysql-u root-p "youpassword" as the root user ON the local machine for authorization: grant all privileges on *. * TO root @ "172.16.16.152" identified by "youpassword" with grant option; overload authorization table: flush privileges; exit mysql database: exit

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

Log ON to mysql: mysql-u root-p "youpassword" as the root user ON the local machine for authorization: GRANT select, insert, update, delete ON *. * TO root @ "172.16.16.152" identified by "youpassword"; reload authorization table: flush privileges; exit mysql database: exit

4. Use the REVOKE command to delete user authorization. The specific command format is:

REVOKE privileges ON database [. table name] FROM user-name; for a specific instance, log on to mysql: mysql-u root-p "youpassword" on the local machine for authorization: GRANT select, insert, update, delete ON TEST-DB TO test-user @ "172.16.16.152" identified by "youpassword"; delete authorization operation: REVOKE all on TEST-DB from test-user; *** note: this operation only clears the user's related permissions to the 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 mysql database: exit

V. detailed classification of MYSQL permissions:

Global Management permission: FILE: read and write files on the MySQL server. PROCESS: displays or kills service threads of other users. RELOAD: RELOAD Access Control tables and refresh logs. SHUTDOWN: Shut down the MySQL service. Database/data table/data column permissions: ALTER: Modify existing data tables (such as adding/deleting columns) and indexes. CREATE: CREATE a new database or data table. DELETE: DELETE table records. DROP: delete a data table or database. INDEX: Create or delete an INDEX. INSERT: Add Table records. SELECT: displays/searches for table records. UPDATE: Modify existing records in the table. Special permissions: ALL: allow to do anything (same as root ). USAGE: Only logon is allowed. Other operations are not allowed.

Summary

The above section describes how to install mysql on centos and set remote access. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in time!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.