Home >Database >Mysql Tutorial >How to set root password in mysql

How to set root password in mysql

PHPz
PHPzOriginal
2023-04-20 10:12:431395browse

MySQL is a commonly used open source database management system. Many websites and applications need to use MySQL for data storage and management. After installing MySQL, in order to ensure the security of the database, we need to set a root password.

The following are the steps to set the MySQL root password:

  1. Log in to MySQL.

Use the following command to log in to MySQL:

sudo mysql

On the Ubuntu system, sudo permissions are required.

  1. Select the MySQL database.

Use the following command to select the MySQL database:

use mysql;
  1. View the current user and password.

Use the following command to view the current MySQL user:

select User from user;

Use the following command to view the current MySQL password:

select Host, User, Password from user;
  1. Modify the root user's password.

Use the following command to modify the password of the root user:

update user set authentication_string=password('你的新密码') where user='root';

Among them, replace "your new password" with the password you want to set.

  1. Refresh the database.

Refresh the MySQL database using the following command:

flush privileges;
  1. Exit MySQL.

Exit MySQL using the following command:

quit;

Setting the MySQL root password is completed.

Through the above steps, we can successfully set the MySQL root password to ensure the security of the database. In actual use, we can also configure and optimize MySQL in more detail to meet the needs of various scenarios.

The above is the detailed content of How to set root password 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