Home >Database >Mysql Tutorial >How to create a user in mysql
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 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>
username
with the new username you want to create. hostname
with a hostname that the user can connect to (for example, localhost
or a specific IP address). password
with the user password. Through MySQL Workbench
In the "Create New User Account" dialog box:
Via SQL script
<code class="sql">CREATE USER username@hostname IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO username@hostname; FLUSH PRIVILEGES;</code>
username
and hostname
with the required information. password
with the user password. GRANT
statement grants the user full permissions on all databases and tables. FLUSH PRIVILEGES
statement will flush the permissions table so that the changes take effect immediately. Note
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!