Home  >  Article  >  Database  >  How to delete root account in MySQL

How to delete root account in MySQL

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

MySQL is an open source relational database management system that is widely used in web application development and data interaction between various mainstream operating systems. MySQL provides an easy-to-use, scalable way to store and retrieve data. In MySQL, the root account is the default super administrator account and can perform various management and operation tasks. This article will introduce how to delete the root account in MySQL.

Step 1: Log in to MySQL

First, we need to log in to MySQL. Open a terminal and enter the following command:

mysql -u root -p

Enter the password for the root account and press Enter.

Step 2: Check the root account

Next, we need to check the permissions of the root account. Enter the following command in the MySQL command line interface:

select user, host from mysql.user;

This will list all users in MySQL and their host names. If the root user's host name is "%", it means that the user has access rights from any host. If the hostname is "localhost", it means that the user can only log in locally from the server.

mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| debian-sys-maint | localhost |
+------------------+-----------+

Step 3: Delete the root account

Some users may want to delete the root account in MySQL so that others cannot use the account for illegal access and operations. Deleting the root account in MySQL is very simple. Simply enter the following command in the command line interface:

DROP USER 'root'@'localhost';

This will remove the root account from MySQL.

Step 4: Create a new administrative user

Before deleting the root account, please make sure you have created a new administrative user for MySQL. This allows you to use this user to perform various administrative and operational tasks. The method to create a new user in MySQL is as follows:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

where "newuser" is the name of the user, which can be any name. You will also need to set a password for this user. Please make sure your password is secure and not shared with other accounts.

Step 5: Authorize new users

The last step is to grant permissions to new users. We can provide the new user with appropriate access using the GRANT command:

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

This will grant the newuser user full access to all databases and tables and enable the "GRANT OPTION".

Summary

Deleting the root account in MySQL may cause data security issues, so make sure to create a new administrative user before deleting the root account. If you follow the steps above, you can safely delete the root account and create a new user in MySQL for management and operations.

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