Your cart is currently empty!
Author: alien
-
Khóa học miễn phí MariaDB – Backup Methods nhận dự án làm có lương
MariaDB – Backup Methods
Data serves as the foundation of business and operations, and with various possible threats (e.g., attackers, system failures, bad upgrades, and maintenance errors) out there, backups remain critical. These backups take many forms, and many options exist for creating them with an even wider set of options within those processes. The important things to remember are the database type, the critical information, and the structure involved. This information determines your best option.
OPTIONS
The main options for backups include logical backups and physical backups. Logical backups hold SQL statements for restoring data. Physical backups contain copies of data.
-
Logical backups offer the flexibility of restoring data on another machine with a different configuration in contrast to physical backups, which are often limited to the same machine and database type. Logical backups occur at database and table level, and physical occur at directory and file level.
-
Physical backups are smaller in size than logical, and also take less time to perform and restore. Physical backups also include log and configuration files, but logical backups do not.
Backup Tools
The main tool used for MariaDB backups is mysqldump. It offers logical backups and flexibility. It also proves an excellent option for small databases. Mysqldump dumps data into SQL, CSV, XML, and many other formats. Its output does not retain stored procedures, views, and events without explicit instruction.
There are three options for mysqldump backups −
-
Raw data − Dump a table as a raw data file through the –tab option, which also specifies the destination of the file −
$ mysqldump -u root -p --no-create-info --tab=/tmp PRODUCTS products_tbl
-
Data/Definitions export − This option allows a single or multiple tables to be exported to a file, and supports backing up all existing databases on the host machine. Examine an example of exporting contents or definitions to a file
$ mysqldump -u root -p PRODUCTS products_tbl > export_file.txt
-
Transfer − You can also output databases and tables to another host
$ mysqldump -u root -p database_name | mysql -h other-host.com database_name
Using THE SELECT…INTO OUTFILE Statement
Another option for exporting data employs the SELECT…INTO OUTFILE statement. This simple option outputs the table into a simple formatted text file −
mysql> SELECT * FROM products_tbl -> INTO OUTFILE ''/tmp/products.txt
Its attributes allow formatting the file to your preferred specifications.
Note the following qualities of this statement −
-
The file name must specify your desired location for the output.
-
You need MariaDB file privileges to execute the statement.
-
The output file name must be unique.
-
You need login credentials on the host.
-
In a UNIX environment, the output file is world readable, but its server ownership affects your ability to delete it. Ensure you have privileges.
Using CONNECT in Backups
The CONNECT handler allows exporting of data. This proves useful primarily in situations when the SELECT…INTO OUTFILE operation does not support the file format.
Review the following example −
create table products engine = CONNECT table_type = XML file_name = ''products.htm'' header = yes option_list = ''name = TABLE,coltype = HTML,attribute = border = 1;cellpadding = 5'' select plugin_name handler, plugin_version version, plugin_author author, plugin_description description, plugin_maturity maturity from information_schema.plugins where plugin_type = ''STORAGE ENGINE
Other Tools
Other options for backups are as follows −
-
XtraBackup − This option targets XtraDB/InnoDB databases and works with any storage engine. Learn more about this tool from Percona”s official site.
-
Snapshots − Some filesystems allow snapshots. The process consists of flushing the tables with read lock, mounting the snapshot, unlocking the tables, copying the snapshot, and then unmounting the snapshot.
-
LVM − This popular method employs a Perl script. It gets a read lock on every table and flushes caches to disk. Then it gets a snapshot and unlocks the tables. Consult the official mylvmbackup website for more information.
-
TokuBackup − This solution provided by Percona provides hot backups taking into account the problems and limitations of InnoDB backup options. It produces a transactional sound copy of files while applications continue to manipulate them.Consult the Percona website for more information..
INNODB Considerations
InnoDB uses a buffer pool for performance enhancement. In a backup, configure InnoDB to avoid copying an entire table into the buffer pool because logical backups typically perform full table scans.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc
-
Khóa học miễn phí MariaDB – Sequences nhận dự án làm có lương
MariaDB – Sequences
In version 10.0.3, MariaDB introduced a storage engine known as sequence. Its ad hoc generates an integer sequence for operations, and then it terminates. The sequence contains positive integers in descending or ascending order, and uses a starting, ending, and increment value.
It does not allow use in multiple queries, only in its original query because of its virtual (not written to disk) nature. However, sequence tables can be converted to standard tables through an ALTER command. If a converted table is deleted, the sequence table still exists. Sequences also cannot produce negative numbers or rotate at the minimum/maximum.
Installing the Sequence Engine
Using sequences requires installing the sequence engine, which MariaDB distributes as a plugin rather than binary. Install it with the following command −
INSTALL SONAME "ha_sequence";
After installation, verify it −
SHOW ENGINESG
Remember that after engine installation, you cannot create a standard table with a name that uses sequence syntax, but you can create a temporary table with a sequence-syntax name.
Creating Sequence
There are two methods of sequence creation −
-
Create a table and use the AUTO_INCREMENT attribute to define a column as auto-increment.
-
Use an existing database and use a sequence SELECT query to produce a sequence. The query uses seq_ [FROM] _to_[TO] or seq_[FROM]_to_[TO]_step_STEP syntax.
Best practices prefer the use of the second method. Review an example of a sequence creation given below −
SELECT * FROM seq_77_to_99;
Sequences have many uses −
-
Locate missing values within a column to protect against related issues in operations −
SELECT myseq.seq FROM seq_22_to_28 myseq LEFT JOIN table1 t ON myseq.seq = x.y WHERE x.y IS NULL;
-
Construct a combination of values −
SELECT x1.seq, x2.seq FROM seq_5_to_9 x1 JOIN seq_5_to_9 x2 ORDER BY 5, 6;
-
Find multiples of a number −
SELECT seq FROM seq_3_to_100_step_4;
- Construct a date sequence for use in applications like booking systems.
- Construct a time sequence.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc