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

How to set root password in mysql

PHPz
Release: 2023-04-20 11:14:59
Original
1392 people have browsed it

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
Copy after login

On the Ubuntu system, sudo permissions are required.

  1. Select the MySQL database.

Use the following command to select the MySQL database:

use mysql;
Copy after login
  1. View the current user and password.

Use the following command to view the current MySQL user:

select User from user;
Copy after login

Use the following command to view the current MySQL password:

select Host, User, Password from user;
Copy after login
  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';
Copy after login

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;
Copy after login
  1. Exit MySQL.

Exit MySQL using the following command:

quit;
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template