[
338
]
This will produce an output like the following:
Figure 13.1: Listing MariaDB databases
The output will show some system databases that were created for us, but our new
database should be listed among them. We can also list users just as easily:
SELECT HOST, USER, PASSWORD FROM mysql.user;
Entering this command will result in something similar to the following output:
Figure 13.2: Listing MariaDB users
Chapter 13
[
339
]
In a typical scenario, when installing an application that needs its own database,
we'll create the database and then a user for that database. We'll normally want
to give that user permission to only that database, with only as much permission
as required to allow it to function properly. We've already created the
mysampledb
database, so if we want to create a user with read-only access to it, we can do so with
the following command:
GRANT SELECT ON mysampledb.* TO 'appuser'@'localhost' IDENTIFIED BY
'password';
With one command, we're not only creating the user
appuser
, but we're also setting
a password for it, in addition to allowing it to have
SELECT
permissions on the
mysampledb
database. This is equivalent to read-only access. If our user needed full
access, we could use the following instead:
GRANT ALL ON mysampledb.* TO 'appuser'@'localhost' IDENTIFIED BY
'password';
To double-check that we've executed the command correctly, we can use this
command to show the grants for a particular user:
SHOW GRANTS FOR 'appuser'@'localhost';
Now, our
appuser
has full access but only to the
mysampledb
database. Of course,
we should only provide full access to the database if absolutely necessary. We can
also provide additional permissions, such as
DELETE
(whether or not the user has
permission to delete rows from database tables),
CREATE
(which controls whether the
user can add rows to the database),
INSERT
(controls whether or not the user can add
new rows to a table),
SELECT
(allows the user to read information from the database),
DROP
(allows the user to fully remove a database), and
ALL
(which gives the user
everything). There are other permissions we can grant or deny; check the MariaDB
documentation for more details. The types of permissions you'll need to grant to a
user to satisfy the application you're installing will depend on the documentation for
that software. Always refer to the installation instructions for the application you're
attempting to install to determine which permissions are required for it to run.
If you'd like to remove user access, you can use the following command to do so
(substituting
myuser
with the user account you wish to remove and
host
with the
proper host access you previously granted the user):
DELETE FROM mysql.user WHERE user='myuser' AND host='localhost';
Managing Databases
Do'stlaringiz bilan baham: |