SoFunction
Updated on 2025-04-07

How to solve the problem of mysql without root user

MySql solves mysql without root user

I found out that mysql didn't have root user at the beginning

Let’s talk about the impact of this problem first. This is related to solving the problem. It is necessary to explain that there is no user in my user table, including root, so I have to give permissions at the beginning to facilitate subsequent operations:

vim /etc/
skip-grant-tables     #exist[mysqld]Add this line below,Ignore permission table

Then restart mysql:

/etc//mysqld restart

Start solving the problem

Let’s talk about the solution steps first:

  • Create a root user
  • Give root all permissions

process

  • 1. Create a root user:
create user 'root'@'localhost' identified by '123456';

localhost means local. When logging in with MySQL, you do not need to specify IP login.

This step may report the following error. If there is no error, skip (directly to the permission step), and use the following method to solve it:

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

  • enter:
flush privileges;
  • Recreate the user again at this time:
create user 'root'@'localhost' identified by '123456';
  • If the error is reported again, if there is no error in this step, it will jump directly to the step of granting permissions. The following operations for the error are reported:
drop user 'root'@'localhost';
  • Recreate the user again:
create user 'root'@'localhost' identified by '123456';

As a result, there was no error reported again and the root user was created successfully.

  • 2. Give root permissions as follows:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; #Grant all table operations permissions for all librariesmysql> flush privileges;
mysql> exit;
  • There is no error at this point, indicating that it has been successful, but the initial configuration file needs to be restored:
vim /etc/
  • Delete the configuration file:
skip-grant-tables
  • Exit and restart mysql:
/etc//mysqld restart

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.