27

I'm pretty new to using Linux but am setting up my MySQL databases on an Amazon ec2 instance. I followed some directions I found about resetting the user login pass by using the --skip-grant-tables option of MySQL. Now I am trying to add a user and can't figure out how to turn that option off.

This is what I'm trying to do:

mysql> GRANT CREATE,SELECT,INSERT,UPDATE,DELETE ON ...my db username and pass

but I get this error:

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

How do I turn this option off?

6 Answers 6

46

Login to mysql

 mysql -u root -p

Then execute:

FLUSH PRIVILEGES;

http://dev.mysql.com/doc/refman/5.0/en/server-options.html http://dev.mysql.com/doc/refman/5.0/en/mysqladmin.html

0
6

You can make this done by using below steps.

[root@backups1 mysql5.7]# bin/mysqld_safe --skip-grant-tables --user=mysql

connect to your mysql without password.

mysql> flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '';
mysql> flush privileges;

switch to normal mode of mysql then connect without password.

This surely will work for you.

1
  • Doesn't work with mariadb. Commented Jan 3, 2021 at 6:33
4

Just stop and restart MySQL normally.

2

Slight modifications from @mansur ali

MYSQL 8, Ubuntu 18.04

[ubuntu@ip-172-31-39-173]$  sudo /usr/bin/mysqld_safe --skip-grant-tables --user=mysql

connect to your mysql without password in another shell by executing

$ mysql

then

mysql> flush privileges;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '';
mysql> flush privileges;
mysql> quit;

switch to normal mode of mysql then connect without password.

This surely will work for you.

1

Yesterday I've encountered similar issue. The server was using Amazon Linux 2 as OS and the official yum repository (the el7 ones) as the installation means.

Especially when you are using the MySQL of the official yum repo, MySQL would be installed as a systemd service. In such case, you can check how MySQL process is launched by executing following command: sudo service mysql status -l. This results in description of the current status of the current mysql service. Of those descriptions, I could find following line:

  Process: 26474 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS

In my environment, it turned out that the MYSQLD_OPTS variable was set with value --skip-grant-tables option by the systemd process. To confirm the environment variables set by systemd, you can execute sudo systemctl show and look for line starting with Environment=.

To change this environment variable, I executed following command.

sudo systemctl set-environment MYSQLD_OPTS=""

After this operation, I restarted the mysqld service by sudo service mysql restart, and everything was working perfectly.

0

I have an update in solution. If what has been suggested above doesn't fix your problem, then this might be it. I took some time reading the logs, and figured the problem is the encryption algorithm being deprecated.

for starters, start the mysqld in safe mode with skipping grant tables.

> sudo mysqld_safe --skip-grant-tables --user=mysql

Then, I ran,

> mysql

Next, the commands I ran came back with errors as below:

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded

And the logs said,

Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'

Then I ran,

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

I tested this. This worked for me.

2
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Oct 8 at 14:12
  • You don't need flush privileges after GRANT or ALTER USER. It's only needed when you modify the tables in the mysql DB directly. Commented Oct 8 at 22:37

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.