I'm trying to set up a connection to a database on my friend's laptop. I have his IP address and port number, but I can't connect to his machine and I think it's because he hasn't granted me permission. How does he grant me all privileges via the MySQL Workbench?
By below command-
GRANT ALL PRIVILEGES ON *.* TO your_name#'your_ip' identified by 'your_pass';
If you also want grant privileges, so that you can also assign rights then add with grant option at the end of sql.
from workbench gui you can do as per below-
go to server > user and privileges > add account
now you can choose options.
Related
I use MYSQL 8.0.27 and Ubuntu. My problems are user's privileges. I can create and connect to database. It's ok. But when i reboot the machine, the user's privileges lost.
Example create user:
CREATE USER 'usuario'#'%' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON bbdd.* TO 'usuario'#'%' WITH GRANT OPTION;
UPDATE user SET plugin='mysql_native_password' WHERE User='usuario';
If i show privilegies for usuario. I see that ok. But if i reboot my machine and again i show the privilegies mysql says There is no such grant defined for user 'usuario' on host '%'
I switch to MySQL 8 recently; earlier I was using MySQL 5.7 in GCP. I know questions like this have already been asked, but I didn't have any luck. My question is, I want to create a new user just say 'user1' and grant all privileges to a user account on all databases.
The query I am using for user creation:
CREATE USER 'user-1'#'%' IDENTIFIED BY 'user_password';
For privileges:
GRANT ALL PRIVILEGES ON *.* TO 'user-1'#'%';
This privileges query used to work on MySQL 5.7, but when I try to run this query in MySQL 8, I get this error (I logged in as root user and MySQL is in GCP):
SQL Error (1045): Access denied for user 'root'#'%' (using password: YES)
I also tried to run this query one after another like this:
CREATE USER 'user-1'#'%' IDENTIFIED BY 'user_password';
GRANT ALL PRIVILEGES ON *.* TO 'user-1'#'%';
But still I get the same error. I came to know that in MySQL 8 localhost root user have all the privileges, but my server is in Google Cloud, so how can I grant all the privileges to the user I created?
When I run this query in the mysql-8 (I am using HeidiSQL to connect the DB and run query)
SELECT * FROM mysql.user;
I got this output:
In this there are two root users:
For one host is localhost/127.0.0.1 (With all the privilege).
For other host is % (Not have any privilege).
I think I logged in as a user with host-% because my server is in GCP, that's why I cannot give any privilege to the user that I have created. So is there any way to give full permission to the
root#%
so that I can give full permission to the other users, Because I don't think there is any way to log in as a root#localhost
The problem here is that you are trying to create a super user, which is not something supported in cloud SQL, as you can see in this documentation:
Cloud SQL does not support SUPER privileges, which means that GRANT ALL PRIVILEGES statements will not work. As an alternative, you can use GRANT ALL ON %.*.
This alternative mentioned could be enough to grant the permissions you expected.
I have successfully created multiple databases in phpMyAdmin. I would now like to assign an existing user + respective password to all of these new databases by running a script on the SQL tab.
Please can you confirm what script I need to run, or if there is an easier script which can be run via root access, please then confirm the root-command for this?
Use the grant permissions command.
If your database was call "newDatabase" and your user was name "newUser" the command to grant all privileges on all the tables contained within would be:
GRANT ALL PRIVILEGES ON `newDatabase`.* TO 'newUser'#'localhost';
This would restrict the user from access the database only from the localhost, to enable access from all host change localhost to '%'
You then need to refresh the privileges with the following command:
FLUSH PRIVILEGES;
EDIT:
To grant privileges to every database on the mysql server use the following command (notice the *.*):
GRANT ALL PRIVILEGES ON *.* TO 'newUser'#'localhost';
GRANT SELECT, INSERT, INDEX ON `db_name`.* TO 'user'#'%';
change SELECT, INSERT, INDEX in what you need
I have recently started using phpstorm and I'm trying to add data source.
It seems I cannot because my mysql server doesnt accept remote connections.
How do I add IP ranges so it may accept them?
You have to grant privileges to your mysql user for access from your local IP, for example
mysql> GRANT ALL PRIVILEGES
ON database.*
TO 'foo'#'remotehost';
you can also use wildcards (%) to ip or hostname
mysql> GRANT ALL PRIVILEGES
ON database.*
TO 'foo'#'123.123.%.%';
or
mysql> GRANT ALL PRIVILEGES
ON database.*
TO 'foo'#'%.foobar.com';
Refer to the docs for details, below mysql 5.5 refman
http://dev.mysql.com/doc/refman/5.5/en/grant.html#grant-database-privileges
I try to connect my db using host address as my ip address 203.199.209.**,but not able to connect db.if i try to connect my db using host address as localhost it connected successfully.
How to solve this issue?
MySQL grants access based on which host you are connecting from.
Run this command as root:
SELECT user, host FROM mysql.user;
These are the users which exist on your server. Notice the host column.
In short, a user is defined as both a user name (user) and a point of connection (host). When you access your server as localhost, you actually login as some_user#localhost. On the other hand, when you access the sever via its IP address, you actually login as some_user#your.ip.address.here. I guess the latter does not exist on your server.
You may want to create a new user such as some_user#your.ip.address.here or some_user#% (the percent sign is a wildcard; here, it means "any host"):
CREATE USER 'some_user'#'your.ip.address.here' IDENTIFIED BY 'your_password';
GRANT ALL ON your_database.* to 'some_user'#'your.ip.address.here';
If you wish to dig further, see this manual page for more details about MySQL access control, and this page for the CREATE USER syntax.
[edit]
Obviously, as suggested by others, you first need to make sure your server listens to this IP address (203.199.209.**). But if this were not already the case, you should get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on '203.199.209.**' (111)
The error you are getting definitely indicates a permission issue.
For mysql-5.7.15-winx64 (Windows Version), login as "root" user and run the following queries in MYSQL:
CREATE USER 'user'#'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'localhost' WITH GRANT OPTION;
CREATE USER 'user'#'%' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
and then Re-start your MYSQL DB.
For this version of MYSQL DB no changes are required in "my-default.ini" located in the same location as "bin" folder.