Method for mysql7.x to install mysql separately

  • 2021-06-28 14:21:18
  • OfStack

The yum source for CentOS7 seems to have no MySQL by default.To solve this problem, we need to download the repo source for mysql first.

1. Download 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

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

4. Reset your password

Log in first before resetting your password


$ mysql -u root

It is possible to report this error at login: ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2) due to access issues with/var/lib/mysql.

The following command changes the owner of/var/lib/mysql to the current user:


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

Then restart the service:


$ service mysqld restart

Next sign in to reset your password:


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

5. Open port 3306


$ sudo vim /etc/sysconfig/iptables

Add the following:


-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

Restart the firewall after saving:


$ sudo service iptables restart

This allows you to connect to the mysql service from other clients.

Step 5 allows you to enter mysql into control of mysql from the command line and authorize remote login.

GRANT ALL PRIVILEGES ON *. * TO'mymysqlname'@'%'IDENTIFIED BY'123456' WITH GRANT OPTION;After entering the above, you have configured an account with mysql remote connection user name mymysqlname and password 123 456.


Related articles: