G
G
giggigi2012-12-24 12:48:45
MySQL
giggigi, 2012-12-24 12:48:45

MySQL: root user without GRANT, what to do?

Hello.
It turned out that I messed up when transferring the database from one server to another, and transferred it along with the mysql database.
After that, I found that I can't even restart mysql, because the debian-sys-maint user does not have the right to do this, but this is not the point, how to solve this problem later, I already found it.
The fact is that for some reason I have a root user without GRANT. Those. he can do everything, but he cannot create a new user, for example.
mysql -uroot -p

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 900
Server version: 5.5.28-1~dotdeb.0 (Debian)

GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '...' WITH GRANT OPTION;

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

That's all. It turns out that my root user does not have the rights to create users and assign rights.
Please help give the root rights)
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gigigi, 2012-12-24
@gigigi

In general, I found the solution myself)
Just in case, suddenly it will come in handy for someone, the sequence of actions:
1. Do DROP DATABASE `mysql`; thereby killing all users and all rights. You can probably do without it, but the second step didn’t work for me with the already finished table (probably due to different mysql versions before and after the mysql database transfer).
2. Run from the console mysql_install_db which creates this very table.
3. Go to mysql -u root and execute

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'new_pass' WITH GRANT OPTION;
FLUSH PRIVILEGES;

4. Restart: service mysql restart (if it doesn't work, then killall mysqld && service mysql start)
5. PROFIT!

J
JekaRu, 2012-12-24
@JekaRu

Try to manually leave the necessary rights for root in the mysql.user table.

K
KEKSOV, 2012-12-24
@KEKSOV

Try mysql -u root -p -h <host IP> where IP is not 127.0.0.1
sometimes [email protected] and [email protected]* have different rights.
Alternatively, copy the mysql database to yourself (after renaming it) and change the rights of root, and then return it to its place. The server must be off during this time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question