Create non-root users in MySQL (detailed explanation)

1. Use the root account to log in to the MySQL server:

mysql -u root -p

2. Create a new user account using the command CREATE USER.

For example, the following command creates a

  • User: newuser
  • Password: xxxxxx
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'xxxxxx';

Notice:

  • The @'localhost' part of the command specifies that the user is only allowed to connect from the local host.
  • If you want to allow connections from any host, you can use 'newuser'@'%'.
CREATE USER 'newuser'@'%' IDENTIFIED BY 'xxxxxxx';	#任何主机的连接

4. Use the command GRANT to grant permission to the new user.

For example, the following command grants all mydatabase privileges to newuser on the database named test:

GRANT ALL PRIVILEGES ON test.* TO 'newuser'@'localhost';

5. Finally, refresh the permissions for the changes to take effect immediately.

FLUSH PRIVILEGES;

Guess you like

Origin blog.csdn.net/qq_53463544/article/details/129267917