Bog'liq Mastering Ubuntu Server Gain expertise in the art of deploying, configuring, managing, and troubleshooting Ubuntu Server by Jay LaCroix (z-lib.org)
[ 337 ] Notice that there is no space in between the
-p
option and the actual password
(though it's common to put a space between the
-u
option and the username). As
useful as it is to provide the username and password in one shot, I don't recommend
that you ever use that method. This is because any Linux command you type
is saved in the history, so anyone can view your command history and they'll
see the password in plain text. I only mention it here because I find that many
administrators do this, even though they shouldn't. At least now you're aware of this
method and why it's wrong.
The
admin
account we created is only intended for system administrators who
need to manage databases on the server. The password for this account should not
be given to anyone other than staff employees or administrators that absolutely
need it. Additional users can be added to the MariaDB server, each with differing
levels of access. Keep in mind that our
admin
account can manage databases but not
users. This is important, as you probably shouldn't allow anyone other than server
administrators to create users. You'll still need to log in as
root
to manage user
permissions.
It may also be useful to create a read-only user for MariaDB for employees who need
to be able to read data but not make changes. Back in the MariaDB shell (as
root
), we
can issue the following command to effectively create a read-only user:
GRANT SELECT ON *.* TO 'readonlyuser'@'localhost' IDENTIFIED BY
'password';
With this command (and flushing privileges afterward), we've done two things. First,
we created a new user and also set up grants for that user with a single command.
Second, we created a read-only user that can view databases but not manage them
(we restricted the permissions to
SELECT
). This is more secure. In practice, it's better
to restrict a read-only user to a
specific database. This is typical in a development
environment, where you'll have an application that connects to a database over the
network and needs to read information from it. We'll go over this scenario soon.
Next, let's create a database. At the MariaDB prompt, execute:
CREATE DATABASE mysampledb;
That was easy. We should now have a database on our server named
mysampledb
. To
list all databases on our server (and confirm our database was created properly), we
can execute the following command:
SHOW DATABASES;