I connected to MySql by this command:
$ mysql -h localhost
mysql> CREATE USER 'alex1'@localhost IDENTIFIED BY 'password$';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
And now I can't anything (create a new user with CRUD privileges, for instance) because localhost
doesn't have enough privileges. I can't connect to MySql with any other credentials because I don't remember them. How do I grant localhost
privileges to do that or create another user or a schema?
The problem is the user you are logged in as is the default user that will be used to access MySQL. This user does not have access to create other users.
Its not about 'localhost'.
If you know the username of an account that has grant privileges, specify it manually at the prompt:
$ mysql -u root -p -h localhost
Now it will ask you for the password for the root account for MySQL. This is normally the main "superuser" account that has all permissions.
If you don't know the root credentials and you don't have another user that has these permissions, then you need to reset the root password. Follow the steps in the manual for your operating system.