Set/Reset Superuser/Root in MySql

35 views Asked by At

I don't have a superuser in mysql (v8.0, with Linux Mint) and I cannot log into any database or alter any record or table (including the Grant table)

I've tried reinstalling mysql and deleting all files that I've found with 'mysql' in their name so many times but it don't seem to solve it.

I can log using mysql_safe --skip-grant tables, but when I do that, then i cannot edit those grant tables:

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

If i log in normal mode (mysql -u root -p)and i want to add privileges to root user or alter the grant table it states the following:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

1

There are 1 answers

0
Amit Mohanty On

Try this once.

// Stop the MySQL Service
sudo systemctl stop mysql 

// Start MySQL in Safe Mode
sudo mysqld_safe --skip-grant-tables & 

// Connect to MySQL
mysql -u root 

//Update User Privileges
USE mysql;
UPDATE user SET authentication_string=PASSWORD('new_password') WHERE User='root';
FLUSH PRIVILEGES;

// Exit MySQL
EXIT;

// Stop MySQL Safe Mode
sudo pkill mysqld_safe

// Start MySQL Normally
sudo systemctl start mysql

Now, you should be able to log in with the root user and the updated password