Cannot alter user in MySQL database - mysql

I have an issue with connection to MySQL database.
Internet says that error Unable to load authentication plugin 'caching_sha2_password' can be fixed with ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '123';.
The issue is that this command doesn't work. ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password BY '123'; also doesn't work.
First command affects 0 rows and has an error 1 factor authentication method does not match against authentication policy. Please refer ##authentication_policy system variable., second one returns an error Operation ALTER USER failed. Of course I'm replacing 123 with my real admin password.
I'm absolutely out of ideas, I hope I can get some clues why this command doesn't work.
Edit
I think the only solution is to uninstall newest MySQL version and install an older one that actually works. Topic closed.

You need to FLUSH PRIVILEGES after a user update command.

Related

How to revoke and grant permissions to a user with GCP's new managed MySQL 8.0

I had no problems making a test MySQL server and applying permissions a week ago with their MySQL 5.7, but trying out the new 8.0 version, I can't seem to alter permissions as easily, if at all. I'm logged in as root remotely, but a local cloud shell instance does the same.
I'm trying to create a new user that only has access to one database, but I can't seem to get past the part where I revoke all default permissions first.
My method:
CREATE USER 'test_user'#'%' IDENTIFIED BY '{password}';
Gives no error. (I've also tried creating a user through GCP's admin panel)
SHOW GRANTS FOR 'test_user'#'%'; returns GRANT USAGE ON *.* TO `test_user`#`%` (I assume this means the new user has full permissions?)
Then, trying to remove all privileges to start fresh with the user,
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'test_user'#'%';
shows:
Error: UNKNOWN_CODE_PLEASE_REPORT: Access denied for AuthId `root`#`%` to database 'mysql'.
I'm pretty new to Mysql, so I'm unsure if this is my fault or just a bug. Thank you!
First, I would like to point out that GRANT USAGE ON *.* TO test_user#% means the inverse, it means that the user has no privileges ! ( more info: Mysql Reference )
Secondly, I think that's what causing the error is the ALL PRIVILEGES keyword, it may have been removed in v8.0, so just go straight after user creation and grant him the privileges that you want on a table/database.

Sequelize does not suport the MySQL 8 autentication protocol and I'm not getting how to change this protocol

I'm trying to migrate a db with Sequelize working with MySQL 8.0.15, but I'm not able to do that. I keep receiving this error message.
Sequelize CLI [Node: 10.15.0, CLI: 5.4.0, ORM: 5.3.5]
Loaded configuration file "config/config.json".
Using environment "development".
ERROR: Client does not support authentication protocol requested by server; consider upgrading MySQL client
I've tried every single solution for this problem. The thing is when i try to change the MySQL root password the message i get is this one:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Then I did try to change the password validate policy following this procedure
https://dev.mysql.com/doc/refman/5.6/en/validate-password-installation.html
then MySQL crashed cause it's deprecated. Then I tried this one
https://dev.mysql.com/doc/refman/8.0/en/validate-password-installation.html
Then I got this
mysql> INSTALL COMPONENT 'file://component_validate_password';
ERROR 3529 (HY000): Cannot load component from specified URN:
'file://component_validate_password'.
Then I checked where the component is
ls /usr/lib64/mysql/plugin/component_v*
/usr/lib64/mysql/plugin/component_validate_password.so
Anyone can help? I'm realy out of options, now!
Thanks in advance
If you want to use MySQL 5.x style authentication, typically all you have to do is add this to your my.cnf:
[mysqld]
default_authentication_plugin=mysql_native_password
Do this before adding any users. Only use users for connecting via Sequelize, never root.
If you are using MySQL 8.0 then https://dev.mysql.com/doc/refman/5.6/en/validate-password-installation.html then this shouldn't work.
Have used mysql_secure_installation and installed the validate_password_component then?
If yes, in that case, the plugin must already be installed and all you need to do is set validate_password related parameters in the options file (default /etc/my.cnf) and some options require a server restart.
For those who cannot edit system variables (for instance, if you're using a managed database in AWS or DigitalOcean), this works as well:
ALTER USER 'foo'#'bar' IDENTIFIED WITH mysql_native_password BY 'password';
flush privileges;
Or, if you cannot run flush privileges; like me:
DROP USER 'foo'#'bar';
CREATE USER 'foo'#'bar' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT INSERT, SELECT, ... ON mydb.* TO 'foo'#'bar';

mysql cannot grant privilege to user, getting error: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

I am in the process of moving a new application to the Production environment which includes a MySQL DB.
While attempting to grant the required privileges using the command:
GRANT ALTER,CREATE ON `MyDB`.`*` to `ThisUser`#`*` ;
I'm getting the error: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements.
and this, while the passwords (of the root user as well as of the ThisUser) fully satisfy the current policy:
The length of the passwords are above 8 chars,
They include both upper and lower case, as well as digits and special chars (like "!", "#", "$", etc.).
I tried setting the validate_password_policy to LOW but it didn't help either.
Can anyone explain what the issue is and how to resolve it?
Thanks.
To solve this problem change validate_password_policy value:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements:
$ mysql -u root -p
mysql> SET GLOBAL validate_password_policy=LOW;
And grant privileges to your user:
mysql> grant all privileges on DB_NAME.* to 'USER_NAME'#'localhost' identified by 'USER_PASS';
mysql> FLUSH PRIVILEGES;
mysql> exit
$ sudo service mysql reload
$ brew services restart mysql
For me it work when I have added IDENTIFIED BY clause in the GRANT query. You need to use IDENTIFY BY clause when you don't have user already added to mysql.
GRANT ALTER,CREATE ON MyDB.* to 'UserName'#'%' IDENTIFIED BY 'UserPassword';
Eventually, the issue was related to some phantom definition of a user as described in here.
This error some time occurs when you've changed some fields like user host or password but forgotten to flush privileges.
So try:
mysql>flush privileges;
The problem is as a result of the policy difference between your password and the server password policy, what you need to do is to reset the password policy of the server to match that no of your server. Type in the following commands to access the plug-in for the password policies
Sudo MySQL
msql> SHOW VARIABLES LIKE 'validate_password%';
This commands should take you to the table with the password policies of the MySQL server. Now you need to write down your password on a piece of paper and reset the server password policies to match that of your password. To do the type in the following commands.
MySQL> SET GLOBAL validate_password_length = 5; ( this should be according to the length of your password)
MySQL> SET GLOBAL validate_number_count = 0;
MySQL> SET GLOBAL validate_password.policy =LOW;
MySQL> SET GLOBAL validate_password_special_char_count = 0;
Note that there are other policies you could change to suit your current password needs.
Incase you are using a password generator it's best to delete the password plug in all together, use the following commands in case you want to delete all password policies.
MySQL> uninstall plugin validate_password;
I was able to solve this ONLY by first adding the phpmyadmin database and user, then running the installation procedure and entering the same password for the phpmyadmin user there as well. Unfortunately, none of the apache configuration files were set up. I'm switchting to ubuntu from amazon linux 2.

How could I setup a user to be used with an ODBC in MySQL?

I've stablished an user that will be used for reporting in my Database. I've granted just SELECT privileges over the necessary database.
I'm able to log into MySQL from phpMyAdmin for example and I do with the user what is supposed to do.
However, the following error arises once you try to read from an ODBC:
[MySQL][ODBC 3.51 Driver]Access denied for user user#server_ip (using password: YES)
Do I need to do something extra? The access with root doesn't have this problems but, obviously, I don't want to grant all permissions to that user for security reasons.
You must first make sure that the user has your desired access when it connects locally. You can test this using the MySQL Query Browser or MySQL Command Line client.
Now, if there is no issue when tested locally, and if the root user is able to access the tables from the remote machine, then something must be wrong with the user's permissions which prevents it from accessing the tables from the remote host. Check if you have correctly granted the needed permissions to the user. Here is the correct syntax:
mysql> CREATE USER 'custom'#'host47.example.com' IDENTIFIED BY 'obscure';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON expenses.*
-> TO 'custom'#'host47.example.com';
See Adding User Accounts in MySQL Reference Manual.

Mysql "access denied for user" error?

I have just added a new database and imported alot of backed up data to it because of a malfunction in the previous database.
I use php and have my own Ubuntu server.
I use phpmyadmin, and have set all privileges to the user.
I am positive the password, username and host are correct.
But I still get this "Access denied for user 'user'#'localhost' to database 'skuffen2'"
What should I do?
Do I need to set permissions somehow on the server?
Please guide me I am in deep need of help right now...
Thanks
login to mysql using root user, use mysql; select * from db where user where user_name=xxx; and check other table as well, most of the privileges settings are there, or just simply flush privileges;