w3resource

Step by Step MySQL user Account Setup


Create a New User

Write a MYSQL query to create a new user "gaioz_amira" with password "SecurePass123".

Solution:

-- This command creates a new database user named 'gaioz_amira' who can connect from localhost
-- The user is authenticated with the specified password 'SecurePass123'
CREATE USER 'gaioz_amira'@'localhost' IDENTIFIED BY 'SecurePass123';

Explanation:

  • Purpose of the Query:
    • The goal is to create a new user account in the MySQL database.
    • This demonstrates how to use the CREATE USER statement for basic user management.
  • Key Components:
    • CREATE USER 'gaioz_amira'@'localhost' : Specifies the username and host from which the user can connect.
    • IDENTIFIED BY 'SecurePass123' : Sets the password for the new user.
  • Real-World Application:
    • Useful when adding new users to a system, ensuring each user has unique credentials.

Notes:

  • Ensure that the username and host combination is unique.
  • Use strong passwords to enhance security.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to create a new user "analytics_user"@'%' with the password "Comp!exP@ss2025" using the caching_sha2_password plugin.
  • Write a MySQL query to create a new user "test_user"@'192.168.1.100' with a strong password, restricting connections to that specific IP address.
  • Write a MySQL query to create a new user "dev_user"@'localhost' that only allows SSL connections.
  • Write a MySQL query to create a new user "audit_user"@'%' with a complex password and a custom authentication method.

Go to:


PREV : MySQL Security and user Management Home.
NEXT : Grant Privileges to a User.

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

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.