Ram Laxman Yadav bio photo

Ram Laxman Yadav

Ruby on Rails Developer

Email Twitter LinkedIn Github Stackoverflow

Hello friends, I am back with the new problem i.e ‘how to allow remote mysql database connection to a user?’

Now here is an to solve this problem. Here we go:

###Create a new user

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

####Grant permissions

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

The asterisks in this command refer to the database and table (respectively) that they can access—this specific command allows to the user to read, edit, execute and perform all tasks across all the databases and tables.

###Relaod permissions Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.

FLUSH PRIVILEGES;

###Grant different user permissions Here is a short list of other common possible permissions that users can enjoy.

ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
CREATE- allows them to create new tables or databases
DROP- allows them to them to delete tables or databases
DELETE- allows them to delete rows from tables
INSERT- allows them to insert rows into tables
SELECT- allows them to use the Select command to read through databases
UPDATE- allow them to update table rows
GRANT OPTION- allows them to grant or remove other users' privileges

To provide a specific user with a permission, you can use this framework:

 GRANT [type of permission] ON [database name].[table name] TO [username]’@'localhost;

###Revoke permission If you need to revoke a permission, the structure is almost identical to granting it:

 REVOKE [type of permission] ON [database name].[table name] FROM [username]’@‘localhost;

OR Just as you can delete databases with DROP, you can use DROP to delete a user altogether:

 DROP USER demo’@‘localhost;

###Change bind address to access remotely To allow remote mysql database connection the first step to change the mysql’s binding ip. For this open /etc/mysql/my.cnf file and change the bind-address 127.0.0.1 to bind-address 0.0.0.0.

####Restart mysql service After all these just run command sudo /etc/init.d/mysql restart to restart the mysql service.