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.
Related
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 is installed on a Ubuntu server.
I am running Windows 8.
Logging in through Putty. I can log in to database with both root and webadmin user accounts.
I can also log in through my browser, using <server ip address>/phpmyadmin
My problem is when I try to use command line to log in. I am trying that approach because I am developing a webpage to access the database on that server. It fails to connect, so I thought if command line works, the webpage will also work.
commandline:
mysql -u webadmin -p
or
mysql -u root -p
error 1045 (28000): access denied for user 'webadmin'#'localhost'
(using password: yes)
I added an iptables entry to allow mysql and that didn't work.
Also, the firewall on server is inactive.
You need to grant access to the database. You can read the documentation here: https://dev.mysql.com/doc/refman/5.1/en/grant.html
You can run the following (but be careful as it will leave your DB open)
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
That will allow root to connect from any IP and do any operations to the DB. If that still doesn't work, you might also need to run the following before the 2 lines above
CREATE USER 'root'#'%' IDENTIFIED BY PASSWORD '[your password]';
I have a Linux EC2 instance which has MySQL server installed on it.
I can login with MySQL root with this command:
mysql -u root -p
For some reasons I created a user guest using following commands:
CREATE USER 'guest'#'%' IDENTIFIED BY 'passpass';
GRANT ALL PRIVILEGES ON * . * TO 'guest'#'%';
FLUSH PRIVILEGES;
Then I exit from root user and try to login with guest user:
mysql -u guest -p
entered the correct password and got this error:
ERROR 1045 (28000): Access denied for user 'guest'#'localhost' (using password: YES)
I even checked out for the anonymous user .
mysql> SELECT User, Host, Password FROM mysql.user WHERE User='';
Empty set (0.00 sec)
Kindly help. I am not able to connect to MySQL using guest user credentials
MYSQL AWS LINUX EC2 INSTANCE
I was trying to access mysql in AWS linux EC2 instance, but was getting the error:- Error: Access denied for user 'root'#'localhost'. After lot of searching I got the solution which worked for me.
So for mysql community server, the default password is randomly generated whenn you install.
Check /var/log/mysqld.log file, write vim /var/log/mysqld.log in terminal and search for the keyword "temporary password"- you will get the password.
Few configurations are required for mysql- sudo /usr/bin/mysql_secure_installation
it will ask for password then enter the "temporary password" collected earlier. and in the proceding steps question will be asked over there new password could be easily set. then can proceed with
mysql -u root -p.
try by Run the command
grant all on . to 'guest'#'%' identified by 'passpass';
flush privileges;
Thanks
I set up a VM (RHEL6) in our company's private cloud, and installed MySQL.
I opened up remote connections like the following so my coworkers and I could connect to it:
GRANT ALL PRIVILEGES ON `dbname`.* TO 'root'#'%';
FLUSH PRIVILEGES;
Here is the result from SHOW GRANTS FOR 'root'#'%';
| GRANT ALL PRIVILEGES ON `dbname`.* TO 'root'#'%' |
1) My coworker can connect to it from the mysql client on his laptop via
mysql -h <hostname> -u root -p dbname
2) I can create a separate VM and connect to the original VM using the same syntax.
However, on my laptop, I can not connect to it. I receive the following error:
ERROR 1045 (28000): Access denied for user 'root'#'<my-ip>' (using passwo
rd: YES)
I've even specifically opened it for my IP using GRANT ALL PRIVILEGES ONdbname.* TO 'root'#'<my-ip>'; FLUSH PRIVILEGES;, which of course shouldn't be necessary, but it didn't work.
I have restarted the MySQL server (which wasn't necessary for my coworkers).
Any idea what could be causing this?
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.