How to add an anonymous user?

How to add an anonymous user?

Answer Answered by Anel Husakovic in this comment.

The way you check about the users:

select user, password, host from mysql.user;
+------+----------+-----------+
| user | password | host      |
+------+----------+-----------+
| root |          | localhost |
| root |          | ubuntu    |
| root |          | 127.0.0.1 |
| root |          | ::1       |
|      |          | localhost |
|      |          | ubuntu    |
+------+----------+-----------+

You can show grants for the current user(anonymous one)

show grants for current_user();
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+

So if you already have anonymous user and want it to be operable, you can grant privileges for this user:

GRANT ALL ON *.* TO ''@'localhost';
show grants for ''@'localhost'\G
*************************** 1. row ***************************
Grants for @localhost: 
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, 
FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, 
LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, 
CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO ''@'localhost'

But if you have deleted anonymous user and want it back

If you have deleted anonimous account:

delete from mysql.user where user='';
Query OK, 2 rows affected (0.001 sec)

When selecting this account - we see there is none:

select user,host from mysql.user where user='';
Empty set (0.000 sec)

To create it one would do (error):

create user ''@'localhost';
ERROR 1396 (HY000): Operation CREATE USER failed for ''@'localhost'

To solve the problem, flush privileges:

flush privileges;
Query OK, 0 rows affected (0.001 sec)

And run again:

create user ''@'localhost';
Query OK, 0 rows affected (0.001 sec)

To verify we are correct:

select user,host from mysql.user where user='';
+------+-----------+
| user | host      |
+------+-----------+
|      | localhost |
+------+-----------+

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.