Thursday 17 October 2013

How to create a database and a user in Mysql

 [root@exmr-s- ~]# mysql -uroot -pmanjit@123

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5573
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ProjStats          |
| mood       |
| mysql              |
| projectautomation  |
| riewboard        |
| son             |
| test               |
| vtigercrm          |
+--------------------+
9 rows in set (0.00 sec)

mysql> create database grxqa;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| ProjStats          |
| grxqa              |
| moodl       |
| mysql              |
| projectautomation  |
| riewboard        |
| sonar              |
| test               |
| vtigercrm          |
+--------------------+
10 rows in set (0.00 sec)

mysql>  create user grxqa;
Query OK, 0 rows affected (0.03 sec)

mysql> grant all on db_name.* to 'grxqa'@'localhost' identified by 'grxqa';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on grxqa.* to 'grxqa'@'%' identified by 'grxqa';
Query OK, 0 rows affected (0.00 sec)



mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)



Note: The localhost field usually doesn’t have to be edited, but you can set it to the specific address.
The above example grants all privileges, obviously. But you will likely want to limit privileges under many circumstances. These parameters include select, insert, and delete.
Choose all that apply and separate by comma, thusly:
mysql > grant select, insert, delete on db_name.* to 'db_user'@'localhost' identified by 'db_password';


mysql> exit
Bye

To check the user:

[root@eximr-s-022 ~]# mysql -ugrxqa -pgrxqa
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5574
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| grxqa              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> exit


No comments:

Post a Comment