This is an old revision of the document!


Installing MySQL

First of all you will need to have the MySQL extension installed – you can do this through the CLI on microcore

tce-load -wi mysql.tcz

Or through the GUI app browser in tiny core.

Your MySQL installation will auto generate two items of interest '/usr/local/etc/my.cnf' and '/usr/local/var/mysql/'

You will want to copy both these items to a persistent area at a later stage, you have a choice of either adding these items to your filetool.lst, or to your persistent storage medium i.e. HDD or USB

I will talk you through both.

MySQL Settings

Root password

To set up a root password you need to use the following command;

mysqladmin -u root password YOUR_PASSWORD

Entering the MySQL terminal

To create a user you will first need to login to the MySQL terminal using the following command;

mysql -u root -p

Input your password when asked and you will be presented with the MySQL prompt.

mysql> 

Creating a User

To actually create a user, use this command – in this example, the user is 'nickjf20', password 'YOUR_PASSWORD';

CREATE USER 'nickjf20'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';

Creating a Database

To create a database, use this command – in this example, the database name is 'forums'

CREATE DATABASE forums;

Granting Privileges

To grant the user 'nickjf20' every privilege on the 'forums' database use;

GRANT ALL PRIVILEGES ON forums.* TO 'nickjf20'@'localhost';

Persistance

Now you have your initial MySQL settings sorted out, we will go onto making these changes permanent.

You have two options;

  1. Add items to filetool.lst (will require filetool -b every reboot)
  2. Add items to persistent storage mediums i.e. HDD or USB

I personally recommend adding the items to a persistent medium simply because it is safer and easier. If you server loses power for whatever reason, your data will revert to the last time filetool.sh -b was run with the filetool.lst method.

The disadvantages are that the DB's aren't stored in RAM through the second method, meaning higher read/write times and added wear to your HDD / USB.

Filetool method

With this method you must add the following directories and files to your /opt/.filetool.lst

/usr/local/etc/my.cnf
/usr/local/var/mysql

This will restore your MySQL settings and DB's on boot.

Because this restoration occurs after the MySQL extension is loaded, you must reboot the MySQL daemon with the following commands added to /opt/bootlocal.sh

mysqladmin --user=root shutdown
/usr/local/bin/mysqld_multi start 1

With the filetool method you must make sure that before you shutdown, any open connections to the MySQL DBs are closed, otherwise data loss will occur. You can safely shut down the MySQL daemon using the following command;

mysqladmin --user=root --password=YOUR_PASSWORD shutdown

Persistent Storage Method

In this method, you have a much lower chance of data loss, as it does not rely on regular 'doses' of 'sudo filetool.sh -b' to backup your DB's.

First you will want to copy over your my.cnf and mysql directory over to a storage directory. In this case, I will be using the generic hdd – it could be sda1, hda3, sdb e.t.c.

cp -fr /usr/local/var/mysql /mnt/hdd/database/mysql
cp -f /usr/local/etc/my.cnf /mnt/hdd/database/my.cnf

You will then need to add the following commands to /opt/bootlocal.sh, again substituting hdd with your storage device.

rm -fr /usr/local/var/mysql
rm -f /usr/local/etc/my.cnf
ln -s /mnt/hdd/database/mysql /usr/local/var/mysql
ln -s /mnt/hdd/database/my.cnf /usr/local/etc/my.cnf
mysqladmin --user=root shutdown
/usr/local/bin/mysqld_multi start 1

As long as no open, active connections are present on shutdown or crash, no data corruption or loss should occur.

Print/export
QR Code
QR Code wiki:mysql_persistence_guide (generated for current page)