Create a MySQL common user

You can use the following command on the MySQL command line to create a new user:

  1. First open the MySQL command line:
sudo mysql -u root
  1. On the MySQL command line, run the following command to create a new user, for example, username myuserand password mypassword:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
  1. Then, you need to assign permissions to this new user. For example, if you want this user to be able to access all databases and perform all operations, you can run the following command:
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';
  1. Finally, you need to run the following command for the permission changes to take effect:
FLUSH PRIVILEGES;
  1. Now, you can use the new username and password to connect to MySQL myuserin the Python program .mypassword

Please note that this is just a basic example. In actual use, you need to choose the appropriate user name, password and permission settings according to the actual situation. And, for a production environment, it is recommended to assign only necessary permissions to reduce security risks.

Guess you like

Origin blog.csdn.net/m0_57236802/article/details/131296000