Database Reference
In-Depth Information
▼
Analysis
The
mysql
database contains a table named
user
that contains all user
accounts.
user
contains a column named
user
that contains the user login
name. A newly installed server might have a single user listed (as seen here);
established servers will likely have far more.
Tip
Test Using Multiple Clients The easiest way to test changes made to user accounts
and rights is to open multiple database clients (multiple copies of the mysql command
line utility, for example), one logged in with the administrative login and the others
logged in as the users being tested.
To create a new user account, use the
CREATE USER
statement, as seen here:
▼
Input
CREATE USER ben IDENTIFIED BY 'p@$$w0rd';
▼
Analysis
CREATE USER
creates a new user account. A password need not be specified
at user account creation time, but this example does specify a password using
IDENTIFIED BY 'p@$$w0rd'
.
If you were to list the user accounts again, you'd see the new account listed in
the output.
Tip
Specifying a Hashed Password The password specified by
IDENTIFIED BY
is plain
text that MariaDB will encrypt before saving it in the
user
table. To specify the pass-
word as a hashed value, use
IDENTIFIED BY PASSWORD
instead.
Note
Using
GRANT
or
INSERT
The
GRANT
statement (which we will get to shortly) can
also create user accounts, but generally
CREATE USER
is the cleanest and simplest
syntax. In addition, it is possible to add users by inserting rows into
user
directly, but
to be safe this is generally not recommended. The tables used by MariaDB to store user
account information (as well as table schemas and more) are extremely important, and
any damage to them could seriously harm the MariaDB server. As such, it is always bet-
ter to use tags and functions to manipulate these tables as opposed to manipulating
them directly.