A2oz

How to Create a User with Password in MySQL Workbench?

Published in MySQL 2 mins read

Creating a user with a password in MySQL Workbench is straightforward. You can achieve this using the CREATE USER statement, specifying the username and password.

Here's a step-by-step guide:

  1. Open MySQL Workbench: Launch MySQL Workbench on your system.

  2. Connect to a Database: Establish a connection to the desired MySQL database.

  3. Execute the CREATE USER Statement: In the SQL editor, type the following command, replacing username and password with your preferred values:

    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    • username: The desired username for the new user.
    • localhost: The host from which the user can connect. You can specify a different host if needed.
    • password: The password for the new user.
  4. Run the Query: Execute the SQL statement by pressing F9 or clicking the "Execute" button.

  5. Verify the User: You can verify the user's creation by using the SHOW GRANTS statement:

    SHOW GRANTS FOR 'username'@'localhost';

    This will display the privileges granted to the user.

Example:

To create a user named new_user with the password secure_password, you would execute the following command:

CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'secure_password';

Practical Insights:

  • Strong Passwords: Always use strong and unique passwords for your MySQL users.
  • Host Restrictions: You can restrict the user's access to specific hosts by modifying the @'host' part of the CREATE USER statement.
  • Granting Privileges: After creating a user, you need to grant them appropriate privileges to access and manipulate data. Use the GRANT statement for this purpose.

Note:

This guide assumes you have the necessary permissions to create users in your MySQL database.

Related Articles