This question already has answers here:
mysql: cannot create user after delete the user with phpmyadmin
(2 answers)
Closed 9 years ago.
I accidentally all my user accesses to phpMyAdmin and I have no clue how to re institute a user so I can access mysql again.
Right now I have no access to even sign in MySQL when using the commandline and phpMyAdmin just displays an error.
Well, if you managed to delete the root user, I assume you have the ability to restart the mysql daemon. Try killing mysql, and restarting it:
mysqld –skip-grant-tables
then
mysql
Which should give you unfettered access to your user table.
Resetting the Root Password
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
Looks like you've not just delete the table, but also the entire mysql permission database. You need now to find the script 'mysql_install_db'. Once you run it, you will recreate the mysql permissions database. Now you need recreate users for any application you've set up previously.
Related
This question already has answers here:
MySQL Utilities - ~/.my.cnf option file
(2 answers)
Closed 6 years ago.
Today I encountered an issue that I can't find my database created by a ROR project from mysql cli. After some spike, It turns out that I didn't login as root, I just use mysql without any argument. So my question is if you login with a bare 'mysql' command, who you are login as and what is the permission you have?
By the way, the mysql version is 5.5 .
Reply for marked as duplicate:
Actually, I don't believe this is dup with MySQL Utilities - ~/.my.cnf option file; I checked my env, I don't have a default config file and I didn't store any password anywhere. My question is who I'm login as if use a bare mysql command. One clue is when I try to query mysql.user, I got message below. So I think I'm login as #localhost, but where this name come from?
Blockquote
mysql> SELECT host, user, password from mysql.user;
ERROR 1142 (42000): SELECT command denied to user ''#'localhost' for table 'user'
mysql>
Only the users listed in mysql.user table can login.
SELECT host, user, password from mysql.user; -- MySQL before 5.7
SELECT host, user, authentication_string from mysql.user; -- MySQL 5.7 +
For the CLI access, the mysql config file can have your password already typed in. The path and name of that that file file varies in different operating systems and versions of database you use.
Accessing MySQL without password may mean:
Your user account does not have the password at all.
Or, you do not need to type in the password, because your config file contains it already. (This may be your way, in this problem.)
Both the options may be unsafe to use.
Also, see in:
https://easyengine.io/tutorials/mysql/mycnf-preference/
MySQL Utilities - ~/.my.cnf option file
http://kvz.io/blog/2010/03/21/access-mysql-without-password/
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.
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)
Every time I create a database using a custom joomla template quick install the database is created but does not show up in MySQL Database management despite the fact that it most definitely does exist and MySQL database management knows it does because it wont let me create a database with that name due to error "Database already exists".
I want to delete joomlasall database.
Full size image
http://img99.imageshack.us/img99/4995/tempkh.png
If you can not see database but you are sure that it exists, this is definitely permissions issue.
Do
SHOW GRANTS
More info here
You will see that you does not hold global SELECT privilege.
You need to explicitly GRANT permissions with similar command like:
GRANT ALL PRIVILEGES ON DBNAME.* TO 'username'#'localhost';
Instead of ALL you can specify SELECT, INSERT, UPDATE, DELETE , EXECUTE, etc... check this
replace DBNAME with your DB name, username with user for whom you want to grant access and localhost with hostname if DB is used remotly.
To do this, you need GRANT privilege or to be root user.
use same mysql user credentials for Joomla DB connectivity also the one you are using in phpmyadmin.
I accidentally removed most of the privileges from my MySQL root user, including the ability to grant privileges. Is there some way I can restore this user to its original state?
You might still be able to do an UPDATE on table user in database mysql:
USE mysql;
UPDATE user SET Grant_priv='1' WHERE User='root';
FLUSH PRIVILEGES;
If step 3 doesn't work, restarting the MySQL server will have the same effect. If step 2 doesn't work, you need to restore mysql.user from backup. If you don't have a backup, make a backup, reinstall MySQL and then selectively restore your backup, leaving out tables within the mysql database.
UPDATE
You're getting Access Denied during the first step. At this point, you're down to the alternative solutions with backups. There's no way (that I know of or can easily imagine) that you're recovering those tables any other way.
UPDATE 2
The exact error message is basically saying that in addition to losing root's grant privileges, you've dropped root's access to the mysql DB. Without having access to that DB and without having grant privileges, the only way I can see back is to somehow obtain a fresh copy of the mysql DB.
Any chance you have a replication slave set up?