Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've read many threads on SO and a few other places and haven't been able to fix my mysql installation in MAMP.
Background. I made a change to my root user the other day in an attempt to get a local service to connect properly. After rebooting my machine phpmyadmin in mamp no longer displayed any of my dbs and showed "No Privileges" to create a database. I tried many things to restore the privileges that I read here and elsewhere to no avail. --skip-grant-tables does not seem to work. Connecting as root in the shell I don't have permission as localhost but I do as 127.0.0.1.
show grants for root#localhost;
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION
I've installed a fresh installation of MAMP and copied over my DBs. While it works, I've run into instances where DBs are not showing all the tables.
So I have to solve one of two problems. I either have to fix the original install or make it so the all tables show for my dbs in my fresh mamp install.
Lesson learned here is don't be lazy and screw around with your root user locally and just create another login.
UPDATE
When I connect as:
/Applications/MAMP/Library/bin/mysql -uroot -h127.0.0.1 -p
mysql> SHOW GRANTS FOR 'root'#'localhost';
+------------------------------------------------------------------------+
| Grants for root#localhost |
+------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `db`.* TO 'root'#'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------+
But when I connect as:
/Applications/MAMP/Library/bin/mysql -uroot -hlocalhost -p
mysql> SHOW GRANTS FOR 'root'#'localhost';
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'mysql'
mysql> SELECT user();
+----------------+
| user() |
+----------------+
| root#localhost |
+----------------+
mysql> SELECT current_user();
+----------------+
| current_user() |
+----------------+
| #localhost |
+----------------+
So when I connect as localhost either by IP or socket I am somehow not logged in as root. I find this very confusing?
After several days of beating my head on this I discovered the solution. It took a while to put the pieces together because the MAMP installation is a bit different then a standard mysql installation. I still don't understand a few of the details but here we go.
Even though I was logging in as root the reality was that I was an anonymous user indicated by the above and ''#'localhost'. So there is obviously a permissions error which has three parts: username, password, and host. So something about my root account changed (I believe it was the password), but how the whole thing responded was a bit wonky, as in instead of telling me my password and username combo was incorrect, I was getting logged in with no permissions. I believe I exacerbated this situation a bit by running some commands like the below.
mysqladmin -u root password 'password'
In the end here is what I did, and I want to make clear this is the instructions for a MAMP installation on OS X, although I'm sure they can be easily adapted for Windoz.
Big thanks to this thread for helping me see the light on how to resolve this.
Open the Activity Monitor.
Shut down MAMP
Ensure that mysql is shut off in Activity Monitor. Now, you might see a _mysqld process running which might be the default OSX mysql running.
Run the following command, replacing the port number with the one you use. This will start mysql minus the user permissions.
/Applications/MAMP/Library/libexec/mysqld --skip-grant-tables --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock
In your console login to mysql with no creds.
mysql
Run the below commands.
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'username'#'localhost' IDENTIFIED BY 'password';
Shut down mysqld and restart it without the skip-grant-tables option
Login to mysql to confirm that things work.
You will need to fix your phpmyadmin as well. I want to preface this with for some reason I do not understand these changes to not propagate quickly, and suddenly just start working.
Go into /Application/MAMP/bin/phpMyAdmin/config.inc.php and enter the correct credentials for your newly created login. Make sure they are exact including host.
Lastly after phpmyadmin is working go into the mysql.user table and see where things could have gone wrong. It's important to understand what got messed up.
There are a few things about what happened in the above that I would love some clarification on, like why MAMPs phpmyadmin credential changes do not work immediately.
Hope all this helps!
Related
mysql 5.7.22 on centos 7
To be clear I have a root password set up. Usually I log in using
mysql -u root -p
Today I accidentally hit Enter after I only typed
mysql
And I was shocked to find out I had logged in as root user. show grants displays
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root#localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
Then I tried
mysql -u root
It still didn't ask for a password for logging in.
Firstly I thought it was some wired setup issue because I was logging in from localhost. However when I tried to login from web browser using serverIP/phpmyadmin and it does ask for root password.
Does anyone know what was going on? Thanks
I assume you are already ssh'd in as root? If you are, then this would be correct as far as I understand from my experience. As you are logged in as the Root user on the server itself, you have complete control over the entire OS and all its applications. There is no 'privilege escalation', as, being the root server user, you can easily change the root password for MySQL (or indeed any aspect of the MySql installation).
Try logging in to the server as a standard user, and try the same, it should not work unless you have an anonymous user set up.
You can view all the users and their hosts with:
SELECT host, user, authentication_string, plugin FROM mysql.user;
This will show you whether there is a password set (there will be an entry in authentication_string) and also the 'plugin' for the db user (re backward compatibility for earlier versions of MySQL)
There is much information about this error but seems nothing works.
So I try to access to xampp mysql-server using the user root from local network.
mysql -uroot -p -h 192.168.100.48 --port=3306 (connecting from other local computer to xampp server)
But even I put right password (which I use for root) it not work. It works only if I log in using same computer where the server is running. I can use other user which I have specified but not root user. Why?
So how to fix this problem and getting it working?
Does the root user have the correct permissions?
Check the first duplicate link below for full answer - credit to Michael Berkowski:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.1.%'
IDENTIFIED BY 'some_characters'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
Have you tried search SO first? There are quite a few questions like this.
Possible duplicates:
How to grant remote access permissions to mysql server for user?
Remote MySql connection from other server
I have 2 different server, one server (server1) hosts the perl application and the other server (server2) hosts the MYSQL DB (DBNAME= hpdb).
The perl application on server1 is suppose to get mysql results from server2. When I try to do this I get the error message Access denied for user 'userrego'#'server1.domain.com' (using password: YES).
However, when I host the perl application on server2, the application works as expected.
I tried to GRANT ALL PRIVILEGES ON hpdb.* TO 'userrego'#'server1.domain.com' but still couldn't get it to work.
mysql> SHOW GRANTS FOR 'userrego'#'server1.domain.com';
+---------------------------------------------------------------------+
| Grants for userrego#server1.domain.com |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'userrego'#'server1.domain.com' |
| GRANT ALL PRIVILEGES ON `hpdb`.* TO 'userrego'#'server1.domain.com' |
+---------------------------------------------------------------------+
2 rows in set (0.01 sec)
There are a couple of things you should please verify:
Please make sure skip-networking in my.cnf is disabled. If bind-address is set, make sure it is appropriately set, depending on the network config of server2. Do a service mysql restart if you changed anything.
If it still does not work I would verify that the password and source ip is not the issue by (if possible) creating another user to connect with - you can always remove it after testing. Issue a grant with:
GRANT ALL PRIVILEGES ON hpdb.* TO 'userregotest'#'%' IDENTIFIED BY 'xxxxxx'
With that you will be sure of the correct password and that the source ip address is not the issue since any source address will be able to connect.
If none of this works, we might need to inspect things a bit closer.
I have been messing around trying to solve this problem for awhile now and I probably messed something up. I have been going around the forums and nothing has been working. First I forgot my password to root and used the command --skip-grant-tables to try to change it. I am able to login into root now on phpmyadmin with my password just being empty. On phpmyadmin it shows User: root#localhost. Then when I try to create a new database there is only a red x and is says No Privileges.
Also if I try to create a password to root I get an error that says - Can't find any matching row in the user table.
I saw on a forunm that said to run this code
select Host, User, Select_priv from mysql.user
but what I get it SELECT command denied to user ''#'localhost' for table 'user'
thanks for the help.
The following command can be used to set the password for the root user and grant all privileges:
UPDATE mysql.user SET Password=PASSWORD('NewPasswordHere') WHERE User='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost';
FLUSH PRIVILEGES;
Place this SQL code into a text file and save it some place convenient. Then, kill the SQL server. Open a command prompt and cd to the directory where the mysql-nt executable is stored. Execute this command:
mysqld-nt --init-file=sql-file-saved-above.txt
Kill the SQL process you just started and restart the server normally and all should be good. Depending on how you have phpMyAdmin configured, you might need to adjust its configuration if you have the root password saved there.
your best option is to set add a new user with a password and grant FULL privildeges, on you connection use the new user
Open PhpMyAdmin
select "Users"
underneath the know users is the option "add user"
add login information as required
tick the 2 boxes in the "database for users section"
now "Check All" in the Global privideges and click go, new user is then set up and you can use it as your new connection
go to Php My Admin home page of wamp
At the very top in grey you can see your connection is "localhost"
Underneath where you see your connection is local, are 10 tabs which are......
Databases |
SQL |
Status |
Users |
Export |
Import |
Settings |
Binary log |
Replication |
More
as you can see option 4 is "Users"
First off, I did google this but sites are flooded with advice on how to deal with "host name is blocked" issues. (https://www.google.com/search?q=mysql+block+a+host). My issue is a little bit the opposite of that.
With me, I am running a MySQL database and no PHP is involved.
I need to block a certain host-name/IP address from connecting to my database, then I will unblock it. I am hoping there are 2 simple queries for this that I can execute on the MySQL database, I just can't seem to find it anywhere.
I can find the hostnames pretty easily by running the show processlist query and I know I can kill one process at a time, but so many new threads pop up that if I can just block all of them from a certain hostname, that would be ideal. Then I will unblock once I fix a few things.
You can use GRANT to give a non-privileged entry for a user connecting from a specific host, even if you have GRANTed privileges to a wildcard including that host. When authenticating, the most specific host match takes precedence.
For example, suppose you enabled a user to connect from a range of hosts on your local subnet:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'#'192.168.56.%' IDENTIFIED BY 'xyzzy';
Then you could grant the minimal USAGE privilege, which is a synonym for "no privileges" for that user for one specific host within that subnet:
mysql> GRANT USAGE ON *.* TO 'user'#'192.168.56.110';
Subsequent attempts to connect from that host get this error:
$ mysql -uuser -pxyzzy
ERROR 1045 (28000): Access denied for user 'user'#'192.168.56.110' (using password: YES)
The reason this gets an error is that I did this grant for the user with no password. If I try to submit a password, this doesn't match the entry in the privileges table.
Even if the user tries to connect without using a password, he finds he has no access to anything.
$ mysql -uuser
mysql> USE mydatabase;
ERROR 1044 (42000): Access denied for user 'user'#'192.168.56.110' to database 'mydatabase'
You can undo the blocking:
mysql> DELETE FROM mysql.user WHERE host='192.168.56.110' AND user='user';
mysql> FLUSH PRIVILEGES;
And then the IP range will come back into effect, and the user will be able to connect from thathost again.
You can revoke privileges as mentioned above, but this will still allow a user to make a connection to your MySQL server - albeit this will prevent that user from authenticating. If you really want to block/allow connections to your MySQL server based on IP, use iptables.
Have you tried using MySQL Workbench?
You can simply remove ROLES for a specific User/Host from there.