Process order for --skip-grant-tables mysqld - mysql

I have a question about a scenario i currently have. generally the process should work but i can't seem to login successfully afterwards. either getting an incorrect username/password combination or an "unable to select Database" error when logging in with any credentials.
to skip forward a bit i have shutdown the mysql server on the machine and restarted it with the command
/etc/init.d/mysqld --skip-grant-tables
then logged in with mysql -u root -p
obviously this lets me in straight away as it skips the permissions check.
My goal is to change the password on a for a user on a table.
Currently there are three databases on the server we will call them as follows.
INFORMATION_SCHEMA
mysql
gnb
There is a table in gnb called users which has a username an password field. it has a single entry called admin under username which i want to change the password for as that is where the web server pulls the data from.
i have successfully changed the password for this particular user with the command
UPDATE users SET Password=PASSWORD('MyNewPass') WHERE username='admin';
FLUSH PRIVILEGES;
And 1 row is affected and i can visibly see the password hash change. also flushing privileges.
here's where i run into my problem....
once i have reset the password and restarted the mysql server in a normal mode i navigate back to the web server login and attempt to log in with the details that i now have.
i'm met with a "unable to select database" error message.
i'm not sure if i have to do something prior to restarting the database? or do i also have to restart the apache web server? i have tried a mirage of different combinations of things but just can't seem to get it working. if i attempt to log in whilst still in --skip-grant-tables mode then i just get an invalid login attempt.
thanks in advance/
I'm stumped....

I think you may have a misunderstanding about how the MySQL authentication system works.
When an application (e.g. a PHP script) connects to MySQL, the user/password checks against the mysql.users table. It does not check any other table in another database, even if that database (gnb) is the database that contains your application's data.
The fact that you have a table called "users" in your gnb database has no bearing on the MySQL authentication system. Of course you can put any data you want into that table, but it won't be used by MySQL authentication.
You can change passwords with the SET PASSWORD command, or you can UPDATE the mysql.users table directly and then FLUSH PRIVILEGES.

for the future.
second table was storing passwords in MD5.
update the row without using any password commands. simply a row update and update it with the MD5 hash of the password i was wishing to use.
web server then recognized the MD5 string as being the correct password and i was able to gain access.

Related

Cannot login to phpMyAdmin error #1862 - Your password has expired

I installed MySQL, PHP, and phpMyAdmin following this tutorial. Everything works well, i.e., I can start and connect to MySQL through the command line without any error, but the problem is when I try to login to phpMyAdmin, I receive this error:
#1862 - Your password has expired. To log in you must change it using a
client that supports expired passwords.
It might worth saying that my current MySQL password is not the temporary one that I received when I installed MySQL, but I changed it later (before installing phpMyAdmin), and now trying to login to phpMyAdmin with this new (current) password shows me the above error.
What might be the problem?
Ok, finally I did not understand what was the reason for this issue, but the following solution worked for me:
Enter this in terminal (in /usr/local/mysql/bin/) mysqladmin -u root -p password
Enter your password
Enter New password
Done! I could then login from phpmyadmin too!
Hope it help others who have similar problem,
MySQL password has expired
From MySQL 5.7.4 the default value for default_password_lifetime is 360 (a year). If you make no changes to this variable or individual user accounts, all user passwords expire after 360 days (so you get: "Your password has expired. To log in you must change it using a client that supports expired passwords").
To prevent automatic password expiry, log in as root (mysql -u root -p):
For clients that automatically connect to the server (e.g. from scripts.) change the password expiration settings:
ALTER USER 'script'#'localhost' PASSWORD EXPIRE NEVER;
or you can disable auto-password-expiry for all users:
SET GLOBAL default_password_lifetime = 0;
Links I used to understand and fix this
MySQL: Password Expiration and Sandbox Mode
MySQL: Password Expiration Policy
Password expiration policy in MySQL Server 5.7

MySQL workbench - Can't connect to a specific database

I'm facing a strange issue here and it seems impossible to me to connect to my MySQL database.
I have used the workbench few times ago, but it was an older version. The problem with the new one (6CE) is that I can't connect directly to a database - it only allows me to create a connection to the server as a root user and I don't remember this password.
Is there a way to make a connection directly to the dataase itself as in the previous versions, or now only the root is an option. If yes I will have to reset my password.
Make sure that your credentials are still valid, and has proper privileges. If you can log into your mysql-server from terminal (with root account or the user you are trying with), then run "SHOW GRANTS" and see the privileges;
To connect to mysql database you need to have your user account's hostname specific to your IP or wildcard (%).
Similarly you can create a new mysql user with the following command from your server, and then try with this new user.
GRANT ALL ON <db>.* TO 'user'#'<ip or %>' IDENTIFIED BY '<password>' ;
FLUSH PRIVILEGES;
Be careful with the user created above. It will have ALL privilege with the specific database. And using % is actually a bad idea, so user you home machines IP (from where you are trying to connect with Workbench)

MySQL how to find host and user info?

how do I find out what my database hostname and user login is? I've tried localhost and root#localhost but no success.
Failed to connect to database host.domain.com:3306 user:root. Please
check the database settings you provided and verify that MySQL is up
and running.
Assuming that mysql is running and you have credentials that work, you can get all the host and user information from the mysql database once you are running mysql successfully - "select User,Host from mysql.user" for example.
But, it looks like your problem is that you can't log into mysql.
If you don't have a valid credentials to your own database, one has to wonder how you managed to lose them. That happens, however, and the way to reset those credentials is described in detail at http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html.

Recover MySQL root Password

We can reset the mysql password by using the mysqld_safe with --skip-grant-tables option.
Can we reset it without mysql restart?
Can we recover the password instead of Resetting ?
No
No
And there is good reason of both No answers.
You can't just let any non-root user reset your root password without having full admin level access to the MySQL process on that host.
MySQL passwords (like Unix passwords) encryption is 1 way street, they can be reset but cannot be decrypted back.
1) You can update user table in mysql database but only if you still have active connection with enough privileges.
2) You cannot, passwords are not stored, only their hash values, on your login hash of your password is compared to hash stored in mysql and there is no way to find password out of hash other than trying all possible passwords hoping for hash match.
stop mysql service and start it in safe mode
start mysqld --skip-grant-tables
change password normally
see also [1]: http://www.debian-administration.org/articles/442
This is documented in the Official MySQL documentation here:
https://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
I doubt this won't address any and all concerns because you can basically fix any permission or user problem with this method.

Logging in as a different user on MySQL

I created a different user, when I try to log into mysql it will not let me. I think I am missing a step. I am using windows 7. When I log in it automatically asks me for a password. If I enter the root password I can use mysql. If I enter the password I have created for the user, I get an error I cannot read and the program exits. Do I need to first login as root then somehow log in as new user. I am very confused. The code I used to create the new user is here:
Trouble logging into mysql as non root
Try this:
>> mysql -u USERNAME -p
Press enter, and you'll be prompted for the password for USERNAME.
There is no mysql equivalent to Oracle's 'connect' statement in the sense that allows to switch a user once already logged in to a mysql console session.
You may have created the new user, but not given that user sufficient permissions on the database you're trying to manage.