Mysql User Creation: Setting Up a New MySQL User Account

Mysql User Creation: Setting Up a New MySQL User Account

To set up a new MySQL user account, you will need to use the CREATE USER statement in the MySQL server. Here are the steps to create a new MySQL user account:

  1. Connect to the MySQL server. To connect to the MySQL server, you can use the mysql utility:
refer t‮ual:o‬tturi.com
mysql -u root -p

Enter the password for the root user when prompted.

  1. Create the new user. To create a new user, you can use the following syntax:
mysql> CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';

Replace username with the desired username, hostname with the hostname or IP address from which the user can connect, and password with the desired password for the user.

For example, to create a new user named john who can connect from the localhost host, you can use the following command:

mysql> CREATE USER 'john'@'localhost' IDENTIFIED BY 'mypassword';
  1. Grant privileges to the user. After creating the user, you will need to grant privileges to the user using the GRANT statement. The privileges will determine what actions the user can perform on the MySQL server.

For example, to grant all privileges to the user, you can use the following command:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'john'@'localhost';

This will allow the user to perform any action on any database or table on the MySQL server.

Alternatively, you can grant specific privileges to the user by specifying the database and table name, as well as the privileges to be granted. For example:

mysql> GRANT SELECT, INSERT, UPDATE ON database_name.table_name TO 'john'@'localhost';

This will allow the user to perform the SELECT, INSERT, and UPDATE actions on the specified database and table.

  1. Flush the privileges. After granting privileges to the user, you will need to flush the privileges to make the changes effective:
mysql> FLUSH PRIVILEGES;
  1. Disconnect from the MySQL server. Once you have finished creating the user and granting privileges, you can disconnect from the MySQL server by typing exit at the MySQL prompt:
mysql> exit

You should now be able to connect to the MySQL server using the new user account.

Created Time:2017-10-30 10:17:51  Author:lautturi