Sharing the process of downloading the mysql database and the method of remote connection, integrating some online resources and some problems encountered by myself, some commonly used commands will not be introduced one by one. Don't say much, let's start now
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 root:root /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
Method 1, iptables (used before CentOS 7.x version, not recommended)
Open the iptables configuration file:
$vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 3306 -j ACCEPT
yum install iptables-services
installation
$ service iptables restart
$ firewall-cmd --permanent --zone=public --add-port=3306/tcp
$ firewall-cmd --permanent --zone=public --add-port=3306/udp
permanent means permanently valid, that is, restarting will not fail
$ firewall-cmd --reload
6. Create a common user and authorize
Example (login with root user):
mysql > use mysql;
Create a user and set a password: username is the username, localhost is the ip address (localhost is fine), and password is the password
mysql >CREATE USER username@localhost IDENTIFIED BY 'password';
mysql > GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; '%' means that all ip addresses can be connected Refresh permissions mysql > flushn privileges;
Now you can connect to the mysql server from the client, if the connection reports such an error: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.x.xxx' (113) . Because we are centos7, please confirm whether the firewall is turned on. Centos7 is firewall by default.
We can stop it and disable it, then start our familiar iptables and that's it!
Note: The mysql client needs to be installed with the mysql client.