Database Reference
In-Depth Information
When connecting to MariaDB as root, or any other user, we tell the mysql command
line client that we are connecting with a password by using the -p flag. When we do
so we can either specify the password right after the -p flag with no space between,
as shown in the following command line:
mysql -u root -pmypassword
Or we can just leave the -p flag by itself and the client will prompt us for the
password, as shown in the following command line:
mysql -u root -p
Enter password:
It is almost never a good idea to type our password on the command line. The reason
is because status and system logs may record the command. This is very useful for
determining who is connecting and when, but it can be very dangerous as it exposes
the password to anyone who can access the logs. By using just -p and then entering
the password when prompted, the password is not echoed to the screen and is not
logged or displayed.
A situation might arise if we want to create a script that connects to our MariaDB
database at certain times to do some housekeeping or other tasks. Naturally, we want
the user to have rights to only do the things that it needs to do and we want the user to
have a good password. Using the password prompt method will work if we use a tool
such as Expect on Linux, but that may not be available, or work, in all cases. So how do
we connect without exposing the password? The answer is option files.
Option files are just text files, and technically we can create one anywhere, but it
should probably be in a logical location, like in the same folder that the script is in or
in a hidden directory in our home directory.
The contents of the option file can be any of the options we can put into a my.cnf ile,
but for the preceding example of supplying a script with a username and password
the contents are very simple, only three lines, the first starting a client section and
the other two specifying the username and password to use ( scriptuser and
scriptpassword in this example):
[client]
user = scriptuser
password=scriptpassword
 
Search WWH ::




Custom Search