1 like 0 dislike
588 views
in Computers & Internet by | 588 views

1 Answer

1 like 0 dislike
Best answer

The GRANT statement gives you the power to enable all, or a selection of, user privileges for a database or for a specific table. In order to GRANT privileges, first you need to log in to the MySQL server using an SSH client. Once you’ve opened an SSH console, please connect to the MySQL server using the following command: 
 

An example on how to log in to a MySQL server using SSH

$mysqladmin -u db_user password  db_passwd

Note: that db_user and db_passwd are your database username and database password


Once logged on to the server, you will see MySQL's SQL command line. Now you can add specific privileges to a user. Let's for example grant SELECT privileges to a user db_user for database 'db_base'. Here is the SQL query: 

 

An example of how to add SELECT privileges to a user using GRANT

GRANT SELECT ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';

If SELECT is not enough for our user we can add more privileges using a query similar to the one below: 



An example of how to add a selection of privileges to a user using GRANT

GRANT SELECT, INSERT, DELETE ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';

If you want to GRANT ALL the privileges to a user then use this query:

An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';

As you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host. 

Sometimes you need to grant privileges to a user for a specific table. To specify the table, replace '*' in 'db_base.*' with your table's name. 


An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.phonebook TO db_user @'%' IDENTIFIED BY 'db_passwd';

Once you have given the desired privileges for your user, you will need to FLUSH privileges in order to complete the setup and to make the new settings work. To do so, run this command within the SQL command prompt: 



An example of how to FLUSH privileges

FLUSH PRIVILEGES;

 

by

Related questions

1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 25, 2015 in Education & Reference by Simmi (620 points) | 138 views
0 like 0 dislike
3 answers
asked Jan 20, 2014 in Education & Reference by Sam (1.4k points) | 447 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 8, 2013 in Education & Reference by Jatin | 486 views
0 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,225 questions
1,370 answers
559 comments
2,099 users