Can't connect to MySQL with hostname wildcard - mysql

I installed MySQL to my Mac (with MAMP installer) and have a problem. When I create a user with "#%" hostname this way:
CREATE USER 'test'#'%' IDENTIFIED BY 'test';
and I try to connect via CLI: mysql -u test -ptest, I get this error:
ERROR 1045 (28000): Access denied for user 'test'#'localhost' (using
password: YES)
But when I change hostname to localhost:
RENAME USER 'test'#'%' TO 'test'#'localhost';
it works.
Any idea how to make MySQL use the wildcard?
Thanks.

As YaK suggests, it is because of anonymous user ''#'localhost' created by MySQL installation. Problem was solved after removal of this user. Thanks a lot YaK!

Related

How do I grant permissions to users in mysql?

How do I grant permissions to users in MySQL?
This is the order in which I tried:
First, connect from EC2 SERVER to MYSQL CLIENT RDS.
After connecting, MYSQL created a user to give you permission.
An error occurs when giving the user permission.
My attempt:
mysql> CREATE USER 'injekim'#'125.128.63.112' IDENTIFIED BY 'k12345678!!';
Query OK, 0 rows affected (0.02 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'injekim'#'125.128.63.112' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'#'%' (using password: YES)
ERROR 1045 (28000): Access denied for user 'root'#'%' (using password: YES)
Also, I found similar error information in stackoverflow, but I couldn't solve it.
MySQL ERROR 1045 (28000): Access denied for user 'bill'#'localhost' (using password: YES)
How can I authorize the user who created it?
It looks like you are not logged into the host machine. To use the root user, you should actually be logged into the machine (ssh or rdp) that is hosting the MySQL server.
Example, let's say I am setting at my Mac but need to give a new user access to a MySQL database that is running on a server with an IP address of 192.168.1.10. Assuming it's a Linux server I would ssh to the server from my Mac's terminal by running:
ssh myuser#192.168.1.10
You can now either:
Log into MySQL as root by running: mysql -u root -p (you will be prompted for the password)
Or,
You could become the root user. In my case, I would run the following:
sudo su. Now that you are the root user, you can log into MySQL by running:
mysql -p
If you need an example in a Windows environment, let me know. It will be the same basic idea, but using RDP instead of ssh. From your local machine, get a session on the actual server running MySQL and then log into MySQL as root from the server.

MySQL said: Access denied for user 'root'#'localhost' (using password: NO)"

I am trying to create a database with Sequel Pro and it keeps coming up with an error "Unable to connect to host because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'root'#'localhost' (using password: NO)"
I have mySQL server running on my Mac. Not sure what I am doing wrong. Any help would be appreciated.
Newer versions of MySQL use a temporary password after setup, and you can use mysqladmin to set it to something permanent.
mysqladmin -u root -p password

Reset MySQL Password on Homestead

I'm running Homestead via Vagrant for a local Laravel install. I logged into Homestead via ssh (vagrant ssh), and connected to MySQL using the host localhost, user homestead, password secret. I was able to connect successfully, and running show databases; tells me there's an information_schema database in there. I thought all was well and I could create a new database for my Laravel project and get going.
Unfortunately, running CREATE DATABASE mynewdb; returned:
ERROR 1044 (42000): Access denied for user 'homestead'#'localhost' to database 'mynewdb'
I tried giving the homestead user some more privileges via:
GRANT ALL PRIVILEGES ON mynewdb.* TO 'homestead'#'localhost' WITH GRANT OPTION;
But get back a similar access denied message:
Access denied for user 'homestead'#'localhost' (using password: YES)
I tried a few other variations of that command, using '%' instead of 'localhost', for instance, but it seems like my homestead user just doesn't have the priviliges needed to administrate this db fully.
I thought I should be able to simple restart the mysql service with the --skip-grant-tables flag, and then login as homestead or root and have full privileges. This also failed to work:
vagrant#homestead:~$ sudo /etc/init.d/mysql stop
[....] Stopping mysql (via systemctl): mysql.servic[.ok
vagrant#homestead:~$ sudo /etc/init.d/mysql start --skip-grant-tables
[....] Starting mysql (via systemctl): mysql.servic[.ok
vagrant#homestead:~$ mysql -h localhost
ERROR 1045 (28000): Access denied for user 'vagrant'#'localhost' (using password: NO)
vagrant#homestead:~$ mysql -h localhost -u homestead
ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: NO)
vagrant#homestead:~$ mysql -h localhost -u root
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
vagrant#homestead:~$ mysql
ERROR 1045 (28000): Access denied for user 'vagrant'#'localhost' (using password: NO)
After those attempts, I logged in with homestead and secret, just to check and see if anything had changed:
vagrant#homestead:~$ mysql -h localhost -u homestead -p
mysql> create database mynewdb;
ERROR 1044 (42000): Access denied for user 'homestead'#'localhost' to database 'mynewdb'
Finally, I noticed in my homestead.yml file that there was an entry that looked like this:
databases:
- homestead
I modified this entry to:
databases:
- homestead
- mynewdb
And then rebooted the homestead VM:
vagrant halt
vagrant up
And then tried again to create the new datbase with the homestead MySQL user. None of this did anything, access is still completely denied for the homestead user trying to do just about anything.
Suggestions to gain access?
I didn't have the patience to try and solve this, as it clearly was not acting right at all. I finally just destroyed the Homestead VM and all its files after backing up my configuration, and reinstalled the machine. Booted it up, and how the homestead user has full access as it should. Not sure what the heck could have happened to it last time, but the lesson here is: Initializing new VM's is cheap, fighting with the wrong permissions is expensive.
If anyone has an explanation as to how I could have fixed this, I'll accept their answer. Otherwise, reinstalling Homestead seems to be the fastest solution.
To login into MySQL as root user, you can use:
mysql -u root -p
and then enter your MySQL password.
To login as another user, you will have to create that user first and grant him privileges.
Create the user using - change newuser to the username you want and password to your password of choice.
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
Sadly, at this point newuser has no permissions to do anything with the databases.
Therefore the first stage is to grant the user the privileges to do 'things'.
To grant all privileges (select, create, delete, update, drop, etc) on all databases and tables, run:
GRANT ALL PRIVILEGES ON * . * TO 'newuser'#'localhost';
To grant a specific privilege on a particular database and table, just run:
GRANT [type of privilege] ON [database name].[table name] TO '[username]'#'localhost';
If you ever need to deny or revoke a certain privilege, just run:
REVOKE [type of permission] ON [database name].[table name] FROM '[username]'#'localhost';

MySQL server access denied while connecting

I have installed Mysql on Mac os 10.7 using dmg installer, it got installed at location /usr/local/mysql I also installed MySQL.prefpane, where I can start and stop the server using services.
i am facing below problems.
mysql> create database test ;
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'ets'
same happens when I am trying to invoke mysql by using below command
./mysql -u root root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Even when I created a connection using Eclipse to mysql db then also I got similar kind of exception.
Just want to know after installation do I need to make any further configuration related to user management and access privileges?
Try this,
./mysql -uroot -pPassword
To give the user all priviliges, execute this command:
GRANT ALL PRIVILEGES ON *.* TO root#'%' IDENTIFIED BY PASSWORD 'yourpassword' WITH GRANT OPTION
Also try
CREATE SCHEMA test;

MySQL - granting permission

I don't get how to give a user permissions in MySQL.
I am using MySQL RDS on aws. I am creating a user and need access to the reports database. I created a hash password and ran the below.
SELECT PASSWORD('Test123');
GRANT ALL PRIVILEGES ON reports.* TO 'central'#'localhost'
IDENTIFIED BY PASSWORD '*D1AD25EDF929F55FBFF703358EC527';
mysql -u central -pTest123 -h test.com
ERROR 1045 (28000): Access denied for user 'central'#'112.198.130.xxx' (using password: YES)
Why? What did I do wrong?
You granted permission to 'central'#'localhost' but are attempting to authenticate as 'central'#'112.198.130.xxx'. Either connect from localhost, or grant permission to the appropriate hosts.