Install MySQL using yum under Centos7

Source: Internet
Author: User

The CentOS7 Yum source does not seem to have MySQL by default. To solve this problem, we need to download the MySQL repo source first.

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

3. Install MySQL

$ sudo yum install Mysql-server

Follow the steps to install it, but after the installation is complete, there is no password and you need to reset the password.

4. Reset Password

Before resetting your password, you must first log in

$ mysql-u Root

This error may be reported at login: Error 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2) because/var /lib/mysql access rights issues. The following command changes the owner of the/var/lib/mysql to the current user:

$ sudo chown-r openscanner:openscanner/var/lib/mysql

Then, restart the service:

$ Service Mysqld Restart

Next login to reset Password:

$ mysql-u Root
MySQL > Use mysql;mysql > Update user set Password=password (' 123456 ') where user= ' root '; mysql > exit;

5. Need to change permissions to enable remote connection to MySQL database

This can be confirmed by the following methods:
Root#mysql-h localhost-uroot-p
Enter Password: ******
Welcome to the MySQL Monitor.   Commands End With; or \g.
Your MySQL Connection ID is 4 to server Version:4.0.20a-debug
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
mysql> use MySQL; (This DB holds various configuration information for MySQL)
Database changed
Mysql> select Host,user from user; (View the user's permission condition)
 mysql> Select Host, user, password from user; 
+-----------+------+-------------------------------------------+
| host      | user | password                                   |
+-----------+------+-------------------------------------------+
| localhost | root | * 4acfe3202a5ff5cf467898fc58aab1d615029441 |
| 127.0.0.1 | root | *4acfe3202a5ff5cf467898fc58aab1d615029441 |
| localhost |      |                                             |
+-----------+------+-------------------------------------------+
4 rows in Set (0.01 sec)
As you can see, you can only access it as a host of localhost.
Workaround:
Mysql> Grant All privileges on * * to ' root ' @ '% ' identified by ' 123456 ' with Grant option;
(% means all external machines, if a certain machine is specified, the% is changed to the corresponding machine name; ' root ' means the username to be used.)
mysql> flush Privileges; (Run this sentence to take effect, or restart MySQL)
Query OK, 0 rows affected (0.03 sec)
Check again:
Mysql> Select Host, user, password from user;
+-----------+------+-------------------------------------------+
| Host | user | password |
+-----------+------+-------------------------------------------+
| localhost | Root | *4acfe3202a5ff5cf467898fc58aab1d615029441 |
| 127.0.0.1 | Root | *4acfe3202a5ff5cf467898fc58aab1d615029441 |
|      localhost |                                           | |
| %         | Root | *4acfe3202a5ff5cf467898fc58aab1d615029441 |
+-----------+------+-------------------------------------------+
4 rows in Set (0.01 sec)

Install MySQL using yum under Centos7

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.