Home  >  Article  >  Database  >  How to create a user in mysql

How to create a user in mysql

下次还敢
下次还敢Original
2024-04-14 19:39:49321browse

There are three ways to create a user in MySQL: execute the CREATE USER statement through the MySQL command line; create a new user account in the "Users and Privileges" node through MySQL Workbench; execute CREATE USER through a SQL script , GRANT and FLUSH PRIVILEGES statements.

How to create a user in mysql

How to create a MySQL user

Creating a user in MySQL is a basic database administration task. There are several ways to do this.

Via the MySQL command line

CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';
  • Replace username with the new username you want to create.
  • Replace hostname with a hostname that the user can connect to (for example, localhost or a specific IP address).
  • Replace password with the user password.

Through MySQL Workbench

  1. In MySQL Workbench, connect to your database server.
  2. In the "Database" tab, right-click the "Users and Privileges" node and select "New User Account...".
  3. In the "Create New User Account" dialog box:

    • Enter the name of the new user.
    • Enter the host name.
    • enter password.
  4. Click "Apply" to create the user.

Via SQL script

CREATE USER username@hostname IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO username@hostname;
FLUSH PRIVILEGES;
  • Replace username and hostname with the required information.
  • Replace password with the user password.
  • The GRANT statement grants the user full permissions on all databases and tables.
  • The FLUSH PRIVILEGES statement will flush the permissions table so that the changes take effect immediately.

Note

  • Use a strong password to protect your user account.
  • Assign users specific permission levels as needed.
  • Regularly review and update user accounts to ensure security.

The above is the detailed content of How to create a user in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn