rctorr@mavi: ~_010.png

Hacía tiempo que no instala MariaDB de forma nativa en Ubuntu 18.04 y al parece hay algunos pasos extra si uno quiere hacer funcionar MariaDB con cliente que se conectan por medio de la dirección IP del equipo.

Lo primero es actualizar la lista de repositorios con el comando:

$ sudo apt update
Hit:1 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [816 kB]
Get:5 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [24.1 kB]
Get:6 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1032 kB]
Get:7 http://us-west-2.ec2.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [9308 B]
Get:8 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]    
Fetched 2133 kB in 1s (2396 kB/s)                                              
Reading package lists... Done
Building dependency tree       
Reading state information... Done
29 packages can be upgraded. Run 'apt list --upgradable' to see them.
$

Después se inicia la instalación del servidor de MariaDB con el comando:

$ sudo apt install mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
  libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
  liblwp-mediatypes-perl libmysqlclient20 libterm-readkey-perl
  libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
  mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 mysql-common
  socat
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
  libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx mariadb-test
  tinyca
The following NEW packages will be installed:
  galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
  libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
  liblwp-mediatypes-perl libmysqlclient20 libterm-readkey-perl
  libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
  mariadb-common mariadb-server mariadb-server-10.1 mariadb-server-core-10.1
  mysql-common socat
0 upgraded, 29 newly installed, 0 to remove and 29 not upgraded.
Need to get 24.1 MB of archives.
After this operation, 184 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
[...]
$

Ahora se verifica que el servidor se esté ejecutando:

$ systemctl status mariadb
● mariadb.service - MariaDB 10.1.43 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: 
   Active: active (running) since Sat 2019-12-07 09:53:49 UTC; 3min 13s ago
[...]
$

por lo que se comprueba que el servidor está instalado y activo

Ahora para conectarse al servidor desde el cliente de la terminal se ejecuta el siguiente comando:

$ sudo mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 42
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit;
$

Con lo anterior se valida que el servidor está ejecutando, sin embargo no hay clave asignada al usuario root, así que se necesita ejecutar un script para asegurar la instalación de MariaDB Server:

$ sudo mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n


 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
$

En las nuevas instalaciones de MariaDB la forma de autenticar usuarios es por un mecanismo llamado unix_socket que es una forma segura donde sólo se necesita el usuario y no de un password, sin embargo esto sólo permite realizar conexiones desde el mismo servidor, así que si queremos realizar conexiones remotas, hay que cambiar al mecanismo mysql_native_password, eso se realiza con las siguiente instrucciones en SQL:

$ sudo mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select Host,User,plugin from mysql.user where user="root";
+-----------+------+-------------+
| Host      | User | plugin      |
+-----------+------+-------------+
| localhost | root | unix_socket |
+-----------+------+-------------+
1 row in set (0.00 sec)

MariaDB [(none)]> update mysql.user set plugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> select Host,User,plugin from mysql.user where user="root";
+-----------+------+-----------------------+
| Host      | User | plugin                |
+-----------+------+-----------------------+
| localhost | root | mysql_native_password |
+-----------+------+-----------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> update mysql.user set password=PASSWORD("password") where User="root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
$

Ahora se configura el usuario root para que tenga acceso desde cualquier equipo además del servidor (NOTA: Esto puede ser un gran problema de seguridad, así que sólo hacerlo para realizar pruebas y no colocar información sensible). Si el usuario root no va a acceder remotamente, puede saltar este paso.

MariaDB [(none)]> create user 'root'@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to root@'%';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> Bye

Ahora se realiza una prueba de conexión desde un equipo remoto usando la dirección ip o nombre del servidor:

$ mysql -hnombre.dominio.com -uroot -p
password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.43-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Finalmente se valida si el servidor permite o no subir archivos usando el comando LOAD DATA LOCAL INFILE, para ello se usa el siguiente comando en SQL:

MariaDB [Ricardo]> show variables like "local_infile";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | OFF |
+---------------+-------+
1 row in set (0.08 sec)

MariaDB [Ricardo]>

Si la variable local_infile está en OFF entonces no se podrán subir datos al servidor, así que para cambiar el valor a ON se realiza con el comando:

MariaDB [Ricardo]> SET GLOBAL local_infile=ON;
Query OK, 0 rows affected (0.08 sec)

MariaDB [Ricardo]> show variables like "local_infile";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | ON |
+---------------+-------+
1 row in set (0.07 sec)

MariaDB [Ricardo]>

Entonces, a partir de ahora ya se pueden importar datos.