MySql : how to create database user on mysql databbase?

to create new user on mysql database we can use below script;

DB_NAME = KartookShop
DB_USER = Kartook
DB_PASSWORD = password
HOST=localhost

we want to give SELECT,INSERT,UPDATE,DELETE,CREATE,DROP permission on Kartook.


GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON KartookShop.* TO ‘Kartook’@'localhost’ IDENTIFIED BY ‘password’;

this will allow Kartook to connect to KartookShop database from localhost. If you want to give permission to connect remotely you need to update the user table or use “%” instead of localhost.


GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON KartookShop.* TO ‘Kartook’@'%’ IDENTIFIED BY ‘password’;

OR if user account already there and you want to give him remote access you need to update the user table.


mysql> use mysql;
Database changed
mysql> select host, user from user where user=’Kartook’;
+———–+——+
| host | user |
+———–+——+
| localhost | Kartook |
+———–+——+
1 rows in set (0.01 sec)
mysql> select host, user from user where user=’Kartook’;
+———–+——+
| host | user |
+———–+——+
| localhost | Kartook |
+———–+——+
1 row in set (0.00 sec)
mysql> update user set host=’%’ where user = ‘Kartook’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select host, user from user where user=’Kartook’;
+——+——+
| host | user |
+——+——+
| % | Kartook |
+——+——+
1 row in set (0.01 sec)

Now user Kartook should be able to login remotely.

Possibly Related Posts:


Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>