权限MySQL配置添加IP访问权限(mysql添加访问ip)

MySQL的权限设置可以控制用户的访问,因此在服务器中配置添加IP访问权限是一项重要的安全控制。

为了添加IP访问权限,首先我们需要登录MySQL服务器,使用root账户登录MySQL:

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 326
Server version: 5.6.39 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

然后,使用以下命令新建一个用户:

mysql> CREATE USER 'testuser'@'10.10.10.1' IDENTIFIED BY 'testpass';
Query OK, 0 rows affected (0.03 sec)

该操作将在MySQL服务器中创建一个新用户,用户名为testuser,密码为testpass,且该用户只能从IP 10.10.10.1 访问MySQL服务器。

接下来,为该用户设置权限,可以使用如下命令:

mysql> GRANT ALL PRIVILEGES ON db1.* TO 'testuser'@'10.10.10.1' WITH GRANT OPTION;
Query OK, 0 rows affected (0.02 sec)

其中, “db1″ 是MySQL数据库的名字,”testuser” 是用户的名字,”*”表示该用户可以访问db1数据库中的所有表。

最后,使用以下命令刷新MySQL服务器权限:

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)

经过上述操作,10.10.10.1 这个IP的用户就已经可以访问 MySQL 服务器,并有足够的权限执行相关操作。借此,就可以为特定IP限制MySQL服务器访问权限,从而提高服务器安全性。


数据运维技术 » 权限MySQL配置添加IP访问权限(mysql添加访问ip)