MariaDB Archives - Justin Silver https://www.justinsilver.com/tag/mariadb/ Technology, Travel, and Pictures Wed, 27 Apr 2016 20:19:21 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.justinsilver.com/wp-content/uploads/2013/06/cropped-apple-touch-icon-160x160.png MariaDB Archives - Justin Silver https://www.justinsilver.com/tag/mariadb/ 32 32 MySQL / MariaDB Backup & Archive Script https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/?utm_source=rss&utm_medium=rss&utm_campaign=mysql-mariadb-backup-archive-script https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/#respond Fri, 18 Mar 2016 00:04:28 +0000 http://www.justinsilver.com/?p=4021 I am using MariaDB – the open source version of MySQL – and wanted an easy way to backup my databases on a regular schedule without having to do anything when I created or...

The post MySQL / MariaDB Backup & Archive Script appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

I am using MariaDB – the open source version of MySQL – and wanted an easy way to backup my databases on a regular schedule without having to do anything when I created or dropped a database. MariaDB is a drop in replacement for MySQL, so this script should work as is. I put together this base script that will use the show databases command to iterate over each database so that it can be passed to mysqldump. The nice command is used to lower the impact to your regular server work.

Once exported the resulting SQL files are compressed into an archive using tar with bzip2 compression, which saves quite a bit of space over gzip from my tests with this kind of data. After the archive is created the source SQL files are deleted (again using nice) and finally anything in the directory older than the specified archive days value will be deleted.

You will need to create a file called /etc/sysconfig/dbbackup that stores the USERNAME and PASSWORD parameters for the script.

#/bin/bash
#
# MySQL/MariaDB backup script
# Justin Silver
# http://www.justinsilver.com
#
# Use cron to schedule this script to run as frequently as you want.
###################################################################################

# Set properties in this file
SYSCONFIG="/etc/sysconfig/dbbackup"

# User with SELECT, SHOW VIEW, EVENT, and TRIGGER, or... root
#USERNAME="USERNAME"
#PASSWORD="PASSWORD"

# Archive path
ARCHIVE_PATH="/var/backups"

# Archive filename
ARCHIVE_FILE="databases_`date +%F_%H-%M-%S`.tbz2"

# Archives older than this will be deleted
ARCHIVE_DAYS="15"

# Set or override config variables here
if [ -f $SYSCONFIG ]; then
    source $SYSCONFIG
fi

if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
    echo "You must set USERNAME and PASSWORD in $SYSCONFIG";
    exit
fi

# Change working directory
cd $ARCHIVE_PATH

# Get all of the databases
for database in `mysql -u $USERNAME -p"$PASSWORD" -Bse 'show databases'`; do

        # Skip ones we don't want to back up
        if [ "performance_schema" == "$database" ]; then continue; fi
        if [ "information_schema" == "$database" ]; then continue; fi

        # Use Nice to dump the database
        nice mysqldump -u $USERNAME -p"$PASSWORD" --events $database > $database.sql

done

# Use Nice to create a tar compressed with bzip2
nice tar -cjf $ARCHIVE_FILE *.sql

# Remove the SQL files
nice rm -rf *.sql

# Remove old archive files
nice find . -mtime +$ARCHIVE_DAYS -exec rm {} \;

The post MySQL / MariaDB Backup & Archive Script appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/feed/ 0
Upgrade From MySQL to MariaDB on CentOS https://www.justinsilver.com/technology/upgrade-mysql-mariadb-centos/?utm_source=rss&utm_medium=rss&utm_campaign=upgrade-mysql-mariadb-centos https://www.justinsilver.com/technology/upgrade-mysql-mariadb-centos/#comments Tue, 22 Apr 2014 08:57:12 +0000 http://justin.ag/?p=3484 Here is how you upgrade from MySQL 5.5+ to MariaDB 5.5, 5.6 or 10.0. After running MySQL 5.5 for a while and getting tired of not taking advantage of the features and performance enhancements,...

The post Upgrade From MySQL to MariaDB on CentOS appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

Here is how you upgrade from MySQL 5.5+ to MariaDB 5.5, 5.6 or 10.0.

After running MySQL 5.5 for a while and getting tired of not taking advantage of the features and performance enhancements, I took things to the next level and decided to just install MariaDB 10. It’s a drop in replacement for MySQL, which means that MariaDB will be able to use the same client binaries, data files, and configurations but will also support the new features found in the latest version of MySQL, as well as some things only found in the MariaDB fork.

Backup First!

The first things you should do is make a back-up of your existing configuration. MySQL has it’s data in /var/lib/mysql on my server, so I just ran cp -R /var/lib/mysql /var/lib/mysql-bak before getting wild.

Install MariaDB Yum Repository

You will then want to install the yum repository for the version of MariaDB you want to install. There is a pretty handy tool provided by the developers of MariaDB to choose the repository best suited for your system located at https://downloads.mariadb.org/mariadb/repositories/. On my setup – 64 bit CentOS 5.10 – I created a file at /etc/yum.repos.d/MariaDB.repo with the following contents.

# MariaDB 10.0 CentOS repository list - created 2014-04-21 22:57 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos5-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Remove MySQL

Since I already had a database running on this server, the next task is to remove the existing packages on the server. You can see the list of what’s installed with yum list installed | grep mysql. Just uninstall the MySQL packages with yum.

yum -y remove mysql*

Remove InnoDB Log Files

This isn’t a step that I took when I did this the first time, and it resulted in MariaDB not being able to start the mysqld daemon. Trying service start mysqld did nothing at all and running sudo -u mysql mysqld only got me as far as seeing the following error.

140421 23:10:40 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140421 23:10:40 [Note] InnoDB: The InnoDB memory heap is disabled
140421 23:10:40 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140421 23:10:40 [Note] InnoDB: Compressed tables use zlib 1.2.3
140421 23:10:40 [Note] InnoDB: Using Linux native AIO
140421 23:10:40 [Note] InnoDB: Using CPU crc32 instructions
140421 23:10:40 [Note] InnoDB: Initializing buffer pool, size = 128.0M
140421 23:10:40 [Note] InnoDB: Completed initialization of buffer pool
140421 23:10:40 [ERROR] InnoDB: Log file ./ib_logfile2 is of different size 0 bytes than other log files 5242880 bytes!
140421 23:10:40 [ERROR] Plugin 'InnoDB' init function returned error.
140421 23:10:40 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140421 23:10:40 [Note] Plugin 'FEEDBACK' is disabled.
140421 23:10:40 [ERROR] Unknown/unsupported storage engine: InnoDB
140421 23:10:40 [ERROR] Aborting
140421 23:10:40 [Note] /usr/sbin/mysqld: Shutdown complete

After much searching, I found out that I just needed to remove the ib_logfiles before the call to service mysql start.

rm -rf /var/lib/mysql/ib_logfile*

Run mysql_upgrade

Once MariaDB is up and running, you should now be able to connect to the database server. That said, you may not actually be able to run any queries. Many of mine were returning with the error Error in query (1548): Cannot load from mysql.proc. The table is probably corrupted. Running mysql_upgrade to complete the switch to MariaDB did the trick and all was now working as expected.

mysql_upgrade -u root -p

Start MariaDB

I am used to the init.d script being known as mysqld so I accounted for this by running ln -s /etc/init.d/mysql /etc/init.d/mysqld before starting the daemon.

service mysqld start

The post Upgrade From MySQL to MariaDB on CentOS appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/upgrade-mysql-mariadb-centos/feed/ 3
Convert From MyISAM to InnoDB Engine https://www.justinsilver.com/technology/convert-myisam-innodb-engine/?utm_source=rss&utm_medium=rss&utm_campaign=convert-myisam-innodb-engine https://www.justinsilver.com/technology/convert-myisam-innodb-engine/#respond Tue, 22 Apr 2014 08:08:12 +0000 http://justin.ag/?p=3478 If you ever have the need to convert a MySQL (or MariaDB) table from the MyISAM engine to the InnoDB engine, you can use the following script to get it done for an entire...

The post Convert From MyISAM to InnoDB Engine appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

If you ever have the need to convert a MySQL (or MariaDB) table from the MyISAM engine to the InnoDB engine, you can use the following script to get it done for an entire database. There are some caveats of course – InnoDB requires a primary key, does not support fulltext indexes, etc. – but if you’re feeling lazy….

DBUSER=root
DBPWD="my password";
DBNAME="database_name";
mysql -u "$DBUSER" -p"$DBPWD" "$DBNAME" -e \
"SHOW TABLE STATUS WHERE Engine='MyISAM';" | \
awk 'NR>1 {print "ALTER TABLE "$1" ENGINE = InnoDB;"}' | \
mysql -u "$DBUSER" -p"$DBPWD" "$DBNAME"

The post Convert From MyISAM to InnoDB Engine appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/convert-myisam-innodb-engine/feed/ 0