Home > Database > Mysql Tutorial > body text

How to create a user in mysql

下次还敢
Release: 2024-04-14 19:39:49
Original
432 people have browsed it

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

<code>CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';</code>
Copy after login
  • 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

<code class="sql">CREATE USER username@hostname IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO username@hostname;
FLUSH PRIVILEGES;</code>
Copy after login
  • 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!