Label:
There seems to be no mysql in the yum source of CentOS7 by default. In order 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 sources: /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 steps, but after the installation is complete, there is no password, 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 when logging in: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2), the reason is /var/lib/mysql Access rights issues. 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, log 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
In this way, you can also connect to the mysql service from other clients.