Linux learning - install MySQL and set up a remote connection

Install mysql

1. First of all logging in the cloud server
2. Download the rpm files, you can download any file folder
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm

3. Installation rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
when the input y to confirm like, after the installation is complete, the two files in the new directory /etc/yum.repos.d, mysql-community.repo-Community-source.repo and MySQL
. 4. yum install mysql
yum install mysql-community-server

5. Start mysql service
systemctl start mysqld

View mysql status
systemctl status mysqld

6. Set mysql boot

systemctl enable mysqld
systemctl daemon-reload

6.5. Restart mysql
systemctl restart mysqld

7. Look for the root password
mysql After installation is complete, in /var/log/mysqld.log file to generate a default root password. Find the root password by default in the following manner, and then log mysql modify:
grep 'temporary password' /var/log/mysqld.log

8. Log mysql, just find the password for the password
mysql -u root -p

9. Change My Password
set password for 'root'@'localhost'=password('MyNewPass!');

Set up a remote connection

In general we need to use Navicat to connect to the database, but the root account does not have permission to connect remotely, only the machine (localhost) login, so it is necessary to create a new account
create user 'root'@'%' identified by 'password';
the account statement creates a permission is not high, the use of the new statement:

grant all privileges on *.* to 'yangxin'@'%' identified by 'yangxin123456' with grant option;

  • all privileges: said it would grant permission to all users. You may specify a specific permission, such as: SELECT, CREATE, DROP like.
  • on: indicates that these rights on which databases and tables to take effect, format: name of the database table names, here to write "*" indicates all databases, all tables. If I want to apply permissions to a user specified table test library, you could write: test.user
  • to: grant permissions to which user. Format: "username" @ "sign in IP or domain name." % Indicates no limit, you can log on any host. For example: "yangxin" @ ". 192.168.0%", represents yangxin the user can only log in 192.168.0IP segment
  • identified by: Specifies the user's login password
  • with grant option: allows users to express their authorized permissions to other users
  • GRANT can be used to add user permissions, permission will automatically add, does not cover the rights previously granted such permission would let you add a user SELECT, and later gave the user to add an INSERT permissions, the user will have both the SELECT and INSERT permission.

View users and permissions database (localhost on behalf of the account can only log in the unit, expressed in% can log on any host)
SELECT `Host`,`User` FROM `user`;

mysql> SELECT `Host`,`User` FROM `user`;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| %         | fanfeifan     |
| %         | root          |
| %         | yangxin       |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
6 rows in set (0.00 sec)

Check the port number mysql

mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.01 sec)

ok, now use this new account can connect to the database

Reproduced in: https: //www.jianshu.com/p/873ed0ab5419

Guess you like

Origin blog.csdn.net/weixin_33725722/article/details/91143958