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:
mysql
utility:mysql -u root -p
Enter the password for the root user when prompted.
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';
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.
mysql> FLUSH PRIVILEGES;
exit
at the MySQL prompt:mysql> exit
You should now be able to connect to the MySQL server using the new user account.