w3resource

User emma Setup with IP Based Restriction


Create a User with Host Restriction

Write a MySQL query to create a new user "emma" that can only connect from the IP address "192.168.1.100".

Solution:

-- This command creates a new user 'emma' who can only connect from IP 192.168.1.100
-- The user is authenticated with the password 'Pass789'
CREATE USER 'emma'@'192.168.1.100' IDENTIFIED BY 'Pass789';

Explanation:

  • Purpose of the Query:
    • The goal is to create a user with connection restrictions based on the client's IP address.
    • This demonstrates enhanced security by limiting where a user can connect from.
  • Key Components:
    • CREATE USER 'emma'@'192.168.1.100' : Defines the user and the allowed host.
    • IDENTIFIED BY 'Pass789' : Sets the password for the user.
  • Real-World Application:
    • Useful in environments where access should be limited to specific networks.

Notes:

  • Ensure the specified IP address is correct to avoid unintended access restrictions.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to create a new user "emma" that can only connect from the IP address "192.168.1.100" using a secure password.
  • Write a MySQL query to create a new user "emma" restricted to connections from a specific subnet such as "192.168.1.%".
  • Write a MySQL query to create a new user "emma" with host restriction and specify a custom authentication plugin.
  • Write a MySQL query to create a new user "emma" with host restriction and then verify the connection limitations by querying the mysql.user table.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous MySQL Exercise: Grant All Privileges with GRANT OPTION.
Next MySQL Exercise: Restrict User Connection with SSL Requirement.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.