Connect to MariaDB database

Let's connect to the MariaDB database. Use the mysql command to connect to a MariaDB database.

mysql -u username -p database name

If the user name is "kimoto" and the database name is "kimotosystem", it will be as follows.

mysql -ukimoto -p kimotosystem

You will be asked for a password, so enter it to connect.

Specify the port number to connect to the database

If the MariaDB port number is different from the MariaDB default port number, specify the port number to connect.

mysql -ukimoto -P 3306 -p kimotosystem

Specify the host name to connect to the database

Let's specify the host name and connect to the database. If the database exists remotely, you can connect by specifying the remote host name (domain name or IP address).

mysql -h kimotosystem.mariadb.database.azure.com -ukimoto -p kimotosystem

Switch the host name between development and production

How do I switch the host name between the development database and the production database?

The easiest way is to use a web framework that can be defined with environment variables and the configuration file can be changed according to the environment variables.

Define environment variables

First, let's define environment variables. If you are using bash on Linux, define it as "~ / .bashrc".

# Development environment
MYAPP_DATABASE_HOST=kimotosystem-devel.mariadb.database.azure.com
# Production environment
MYAPP_DATABASE_HOST=kimotosystem.mariadb.database.azure.com

Configuration file

For example, in the Mojolicious configuration file "myapp.conf".

my $host = $ENV {MYAPP_DATABASE_HOST};
{
  #Database
  db_dsn => "dbi: mysql: database = kimotosystem; host = $host",
}

You can write this because "myapp.conf" is actually a Perl program that returns a hash reference, not a configuration file.

You can easily switch the database host name between the development environment and the production environment by using a web framework that has a programmable configuration file.

Associated Information