Home  >  Article  >  Database  >  How to log in with the created user in mysql

How to log in with the created user in mysql

下次还敢
下次还敢Original
2024-04-14 19:39:31582browse

To log in to MySQL using the created user, perform the following steps: Connect to the database as the original user with administrative rights. Create a new user and specify username, hostname, and password. Grant the new user the required permissions. Refresh permissions for changes to take effect. Sign out and reconnect with a new username and password. Enter the new user's password to complete the login.

How to log in with the created user in mysql

How to log in using the created user in MySQL

To log in to the MySQL database using the created user, please follow Follow these steps:

1. Use the original user connection

Connect to the MySQL database as an original user with administrative rights, such as the root user.

2. Create a new user

Use the following syntax to create a new user:

<code>CREATE USER '新用户名'@'主机名' IDENTIFIED BY '密码';</code>
  • New username: The name of the new user to create.
  • Hostname: The IP address or hostname from which users can connect (% means any host).
  • Password: The password used by the user to log in.

3. Grant permissions

Grant the new user the permissions needed to connect to the database and perform operations. For example, to grant all permissions, use the following syntax:

<code>GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'主机名';</code>

4. Refresh permissions

Refresh permissions for changes to take effect:

<code>FLUSH PRIVILEGES;</code>

5. Exit and connect using a new user

Quit MySQL and reconnect using the newly created username and password:

<code>mysql -u 新用户名 -p密码</code>

6. Enter the password

When prompted for a password, enter the new user's password.

After the connection is successful, you will log in to the MySQL database using the newly created user.

The above is the detailed content of How to log in with the created user in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn