It is common practice, for example, for each unique MySQL database on a server to have its own unique user associated with it, such that only one single user has authentication access to one single database and vice-versa. In most cases, you’ll be granting privileges to MySQL users based on the particular database that account should have access to. There are a wide range of flags and options available to the command, so you may wish to familiarize yourself with what GRANT can actually do by browsing through the official documentation. The GRANT command is capable of applying a wide variety of privileges, everything from the ability to CREATE tables and databases, read or write FILES, and even SHUTDOWN the server. 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.Now that you are at the mysqlcli prompt, you need only issue the GRANT command with the necessary options to apply the appropriate permissions. An example of how to Grant Privileges in MySQL GRANT ALL PRIVILEGES ON db_base.phonebook TO db_user IDENTIFIED BY 'db_passwd' To specify the table, replace '*' in 'db_base.*' with your table's name. Sometimes you need to grant privileges to a user for a specific table. 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' Īs you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host. 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 IDENTIFIED BY ' db_passwd' These permissions can be any combination of SELECT, INSERT, UPDATE, DELETE, INDEX, CREATE, ALTER, DROP. Here is the SQL query: An example of how to add SELECT privileges to a user using GRANT GRANT SELECT ON db_ base.* TO IDENTIFIED BY ' db_passwd' You can grant users various privileges to tables. Let's for example grant SELECT privileges to a user db_user for database 'db_base'. Now you can add specific privileges to a user. SELECT: The user can read rows from a table. You have created a user who does not have any permissions on any database or table yet. INSERT: The user can add rows to a table. CREATE USER userlocalhost IDENTIFIED BY password. DELETE: The user can delete rows in a table. CREATE: The user can create new databases and tables. ALTER: The user can change the structure of a table or database. Once logged on to the server, you will see MySQL's SQL command line. ALL PRIVILEGES: The user is granted all privileges except GRANT OPTION and PROXY. 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 In order to GRANT privileges, first you need to log in to the MySQL server using an SSH client. The GRANT statement gives you the power to enable all, or a selection of, user privileges for a database or for a specific table. The administrators' control over the MySQL server users is executed through five tables within the MySQL database - the user table, determining whether the user can connect to the server or not, the db, tables_priv and columns_pri tables, specifying which users can access certain databases, tables or table columns from given hosts, and the host table, defining whether an entry within the db table should be extended and with what values. The administration side of the process includes the possibility for the administrators to control certain user privileges over the MySQL server by restricting their access to an entire database or just limiting permissions for a specific table. You can learn more about the users' MySQL management rights in our articles dedicated to the create-user, create-database, create-table and alter-table command options. The MySQL database software offers both administrators and users a great amount of control options.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |