User Tools

Site Tools


useful:mysql-mariadb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
useful:mysql-mariadb [2022/08/13 06:39] adminuseful:mysql-mariadb [2024/03/15 14:36] (current) admin
Line 51: Line 51:
     sudo systemctl start mysql # and it should finally start     sudo systemctl start mysql # and it should finally start
  
 +===== SSH Tunnel to Database =====
 +
 +If the MySQL or MariaDB database is running on a different machine (whether real or virtual) from the application, a connection through a network is needed. Assuming the network cannot be assumed to be secure, some kind of encryption is needed.
 +
 +Various alternatives exist, the main ones being and SSH tunnel, TLS connection, VPN. Of these, the SSH tunnel is the easiest to configure, and also the most efficient.
 +
 +I used to set up SSH tunnels with autossh which provides a means of restarting SSH if it should fail. More recently, I found that it is possible in systems that support systemd to run the tunnel as a service. The service mechanism will handle the restarting without the need for extra software. The creation of tunnels can also be made quite elegant.
 +
 +The solution I have now used is well described at [[https://gist.github.com/drmalex07/c0f9304deea566842490|this Github article]].
 +
 +Except that I had a big problem with one connection, and it seems the fix is to change "LOCAL_ADDR=localhost" to "LOCAL_ADDR=127.0.0.1".
 +
 +
 +===== Data files under /home directory =====
 +
 +By default, this is not allowed and will cause errors. But there are situations where /home is a good place for the data. To fix this in Debian, create and edit this file:
 +
 +     vim /etc/systemd/system/mariadb.service.d/override.conf
 +     
 +Set the contents to:
 +
 +     [Service]
 +     ProtectHome=false
 +
 +It should be possible to achieve this without knowing exactly where the file is by using:
 +
 +     systemctl edit mariadb
 +     
 +but when I tried, it seemed not to work.
 +
 +===== Change collation for all tables in a database =====
 +
 +Remember to set the correct name for the database in this code and make sure output file does not exist:
 +
 +     SET @MY_SCHEMA = "myremos_j41";
 +     SELECT DISTINCT
 +      CONCAT("ALTER TABLE ", TABLE_NAME," CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;") as queries
 +     FROM INFORMATION_SCHEMA.TABLES
 +     WHERE TABLE_SCHEMA=@MY_SCHEMA
 +       AND TABLE_TYPE="BASE TABLE"
 +     INTO OUTFILE '/tmp/convert.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
 +     
 +Then run this command (changing database name as appropriate):
 +
 +     mysql myremos_j41 < /tmp/convert.csv     
  
useful/mysql-mariadb.1660372763.txt.gz · Last modified: 2022/08/13 06:39 by admin