MySQL Backup and Security. Best practices on how to run MySQL on Linux in a secure way Lenz Grimmer <lenz@mysql.com>



Similar documents
Lenz Grimmer

MySQL Backup and Recovery: Tools and Techniques. Presented by: René Senior Operational DBA

A Quick Start Guide to Backup Technologies

DBA Tutorial Kai Voigt Senior MySQL Instructor Sun Microsystems Santa Clara, April 12, 2010

MySQL Backup IEDR

How to install/configure MySQL Database

MySQL Backups: From strategy to Implementation

Database Administration with MySQL

Last month, I covered the historical problems of getting good

Part 3. MySQL DBA I Exam

MySQL backups: strategy, tools, recovery scenarios. Akshay Suryawanshi Roman Vynar

Percona Server features for OpenStack and Trove Ops

A Guide to Securing MySQL on Windows

Setting Up Specify to use a Shared Workstation as a Database Server

How to backup a remote MySQL server with ZRM over the Internet

Zero-Downtime MySQL Backups

S W I S S O R A C L E U S E R G R O U P. N e w s l e t t e r 3 / J u l i with MySQL 5.5. Spotlight on the SQL Tuning

MySQL Administration and Management Essentials

Hardening MySQL. Maciej Dobrzański maciek at

<Insert Picture Here> MySQL Security In A Cloudy World

MySQL Security: Best Practices

MySQL Enterprise Backup User's Guide (Version 3.5.4)

XtraBackup: Hot Backups and More

MySQL Enterprise Backup

The Database Experimental Ranch: MySQL Lab Setup

How To Backup A Database On A Microsoft Powerpoint 3.5 (Mysqldump) On A Pcode (Mysql) On Your Pcode On A Macbook Or Macbook (Powerpoint) On

XtraBackup. Vadim Tkachenko CTO, Co-Founder, Percona Inc Percona Live SF Feb 2011

Installing and Running MOVES on Linux

MySQL backup and restore best practices. Roman Vynar September 21, 2015

Small Systems Solutions is the. Premier Red Hat and Professional. VMware Certified Partner and Reseller. in Saudi Arabia, as well a competent

Restore and Recovery Tasks. Copyright 2009, Oracle. All rights reserved.

Understanding MySQL storage and clustering in QueueMetrics. Loway

Linux Backups. Russell Adams Linux Backups p. 1

This appendix describes the following procedures: Cisco ANA Registry Backup and Restore Oracle Database Backup and Restore

Ingres Backup and Recovery. Bruno Bompar Senior Manager Customer Support

Backup and Recovery using PITR Mark Jones EnterpriseDB Corporation. All rights reserved. 1

BACKUP YOUR SENSITIVE DATA WITH BACKUP- MANAGER

MySQL Enterprise Backup User's Guide (Version 3.5.4)

SSL Tunnels. Introduction

What is included in the ATRC server support

Using Symantec NetBackup with Symantec Security Information Manager 4.5

Fermilab Central Web Service Site Owner User Manual. DocDB: CS-doc-5372

Backup/Restore MySQL Server

HARFORD COMMUNITY COLLEGE 401 Thomas Run Road Bel Air, MD Course Outline CIS INTRODUCTION TO UNIX

Overview. Remote access and file transfer. SSH clients by platform. Logging in remotely

Module 7. Backup and Recovery

Preface Part I. Introduction 1. The Philosophy of Backup Champagne Backup on a Beer Budget Why Should I Read This Book? Why Back Up?

Preparing for the Big Oops! Disaster Recovery Sites for MySQL. Robert Hodges, CEO, Continuent MySQL Conference 2011

Windows Template Creation Guide. How to build your own Windows VM templates for deployment in Cloudturk.

4PSA Total Backup User's Guide. for Plesk and newer versions

LAMP Quickstart for Red Hat Enterprise Linux 4

EVault Software. Course 361 Protecting Linux and UNIX with EVault

Other trademarks and Registered trademarks include: LONE-TAR. AIR-BAG. RESCUE-RANGER TAPE-TELL. CRONY. BUTTSAVER. SHELL-LOCK

MySQL Enterprise Backup User's Guide (Version 3.9.0)

Using Network Attached Storage with Linux. by Andy Pepperdine

Presented by: CSIR-KNOWGATE. KNOWGATE KNOWGATE Website: knowgate.niscair.res.in

PostgreSQL Backup Strategies

Make a folder named Lab3. We will be using Unix redirection commands to create several output files in that folder.

Moving Drupal to the Cloud: A step-by-step guide and reference document for hosting a Drupal web site on Amazon Web Services

Backup Software Technology

RecoveryVault Express Client User Manual

High Availability Solutions for the MariaDB and MySQL Database

Upgrading MySQL from 32-bit to 64-bit

SoftNAS Application Guide: In-Flight Encryption 12/7/2015 SOFTNAS LLC

How to install PowerChute Network Shutdown on VMware ESXi 3.5, 4.0 and 4.1

How To Install Storegrid Server On Linux On A Microsoft Ubuntu 7.5 (Amd64) Or Ubuntu (Amd86) (Amd77) (Orchestra) (For Ubuntu) (Permanent) (Powerpoint

RH033 Red Hat Linux Essentials or equivalent experience with Red Hat Linux..

How To Install Amyshelf On Windows 2000 Or Later

IM and Presence Disaster Recovery System

Online Backup Linux Client User Manual

1. Product Information

Red Hat Linux Administration II Installation, Configuration, Software and Troubleshooting

SIMIAN systems. Setting up a Sitellite development environment on Windows. Sitellite Content Management System

Online Backup Client User Manual Linux

GeBro-BACKUP. Die Online-Datensicherung. MANUAL EXCHANGE 2003, 2007 & FOR THE GeBro-BACKUP "PRO" MANAGER AND HIGHER

Online Backup Client User Manual

CWMS System Backup / Oracle Backup and Recovery

Backup/Restore Microsoft SQL Server 7.0 / 2000 / 2005 / 2008

Determining your storage engine usage

RMAN What is Rman Why use Rman Understanding The Rman Architecture Taking Backup in Non archive Backup Mode Taking Backup in archive Mode

Surround SCM Backup and Disaster Recovery Solutions

CN=Monitor Installation and Configuration v2.0

Incremental Backup Script. Jason Healy, Director of Networks and Systems

Newton Linux User Group Graphing SNMP with Cacti and RRDtool

Adept Backup Solution - Configure Database MySQL Backup Schedule How to configure a MySQL Database Backup. Overview.

Easy Setup Guide 1&1 CLOUD SERVER. Creating Backups. for Linux

MySQL Enterprise Backup User's Guide (Version )

ISPConfig Documentation

Acronis Backup & Recovery 10 Server for Linux. Command Line Reference

Lucid Key Server v2 Installation Documentation.

1 Context Manage users and group accounts and related system files [4]

Obackup v1.84 RC2 Documentation

DigiVault Online Backup Manager. Microsoft SQL Server Backup/Restore Guide

Backup of ESXi Virtual Machines using Affa

Applications Manager Best Practices document

Lotus Domino Backup Strategy

Hervey Allen. Network Startup Resource Center. PacNOG 6: Nadi, Fiji. Security Overview

13.1 Backup virtual machines running on VMware ESXi / ESX Server

Access Control System Database and Linux Administration. V /8/2010 Ben Davis

Host Hardening. Presented by. Douglas Couch & Nathan Heck Security Analysts for ITaP 1

Transcription:

MySQL Backup and Security Best practices on how to run MySQL on Linux in a secure way Lenz Grimmer <lenz@mysql.com>

Introduction In this session you will learn best practises on how to configure and run MySQL on Linux in a secure way. It will give an overview about the security mechanisms built into MySQL and how they can be improved and accompanied by security mechanisms provided by the Linux Operating system. In addition to to improving the security of a MySQL installation, several MySQL backup possibilities/tools and strategies for Linux are discussed. 2

Session content Improving MySQL Security On the MySQL server level One the Linux OS level MySQL backup methods Physical vs. logical backup OSS tools suitable for backup purposes Commercial backup solutions 3

Improving MySQL security Securing MySQL is an essential part of the post-installation process While the default installation is pretty secure by itself already, some additional steps have to be performed In addition to the facilities provided by MySQL itself, make use of additional security features provided by the OS 4

MySQL Server post-installation Make sure to set a password for the root account $ mysql u root mysql mysql> SET PASSWORD FOR root@localhost=password('new_password'); Remove the anonymous account or assign a password to it Remove the test database, if you don't need it All the above steps can be performed by running the mysql_secure_installation script included in the Unix distributions 5

Connect Access Control Check When a user connects the server checks in the user table to see if it can find a matching entry for the username, host and password Query When a query is executed the server checks the user, db, tables_priv and column_privs tables 6

Query Access Control Do you have sufficient privileges to execute the query? Query user db false false tables_priv false columns_priv false Permission denied true true true true Query executed 7

MySQL Server security hints Use the bind address option in my.cfg to bind the TCP port to a specific interface (e.g. 127.0.0.1) Consider the skip networking option, which only allows connections via the local socket file Allow access from selected hosts only Restrict access to the mysql.user table to the root user Learn how to use the SHOW GRANTS, SET PASSWORD and GRANT/REVOKE statements Or use phpmyadmin or MySQL Administrator 8

MySQL Server security hints Restrict PROCESS/SUPER/FILE privileges to a minimum Do not store any plain-text passwords in your database. Instead, use MD5(), SHA1() or some other one-way hashing function. Disable LOAD DATA LOCAL by setting localinfile=0 in my.cnf Always use a non-privileged account to run mysqld 9

MySQL Server security hints For the paranoid: replace the root account with a different, harder to guess one to avoid brute-force dictionary attacks make sure to remove or clean up the history file of the mysql command line client, if you used it to edit or add user accounts/passwords on the command line 10

Views and Stored Procedures Views can be used to restrict access to certain columns of tables Stored Procedures can be used to shield the tables from being accessed by the user/application directly Plug: Now available in MySQL 5.0! 11

OS Level security Using MySQL on Linux adds a few more options to improve the security of running MySQL Improving access restrictions Reducing security risks Securing data and communication 12

Improving access restrictions Lock down the permissions on the data directory with chown and chmod users won t corrupt table data users won t see data they aren t supposed to see The log files must also be kept secure: users might again see data they aren t supposed to see queries such as GRANT are stored in the logfiles, anyone with log file access could then obtain user passwords Don't allow normal user logins on the DB server 13

Reducing security risks Use iptables to firewall the server Run MySQL in a chroot() jail Enable SELinux or Novell AppArmor Run the MySQL server in a virtual machine Xen UML (User Mode Linux) VMware 14

Securing data and communication Encrypt network traffic OpenSSL SSH tunnel OpenVPN Cipe Encrypt the data directory cryptoloop devices dm-crypt 15

Backing up MySQL data When do you need backups? What needs to be backed up? How can backups be performed? 16

When Do You Need Backups? Hardware failure When a system crash occurs some of the data in the databases may be lost A hard-disk failure will most certainly lead to lost data User failure A user may issue DROP TABLE or DELETE FROM statements that he or she later regrets Someone (an administrator?) might try to edit the table files with text editors, usually leading to corrupt tables 17

What needs to be backed up? Database content for full backups logical or physical backup Log files for incremental backups point-in-time recovery 18

The Data Directory By default all databases as well as most log and status files are stored in the data directory A default data directory is compiled into the server /usr/local/mysql/data/ (tarball) /var/lib/mysql (RPM) The data directory location can be specified during server startup with datadir=/your/path/ If you don t know the location of the data directory you can find it out with: mysql> SHOW VARIABLES like 'data%'; 19

The Binary Log Contains all SQL commands that actually change data Also contains additional information on each query e.g. query execution time The binary log is not stored in text format, it is stored in a more efficient binary format You must use mysqlbinlog to access the log contents Turned on with log bin[=file_name] The update logs are created in sequence e.g. file_name bin.001, file_name bin.002, etc. The binary log is compatible with transactions mysqld creates a binary log index file which contains the names of the binary log files used 20

Managing The Binary Log The purpose of the Binary Log is to Ease crash recovery Enable replication SHOW MASTER LOGS shows all binary log files residing on the server With FLUSH LOGS or when restarting the server a new file is used RESET MASTER deletes all binary log files PURGE MASTER deletes all binary log files up to a certain point 21

The Error Log When the server is started with mysqld_safe all the error messages are directed to the error log The log contains info on when mysqld was started and stopped as well as errors found when running $ cat /var/log/mysql.err 000929 15:29:45 mysqld started /usr/sbin/mysqld: ready for connections 000929 15:31:15 Aborted connection 1 to db: 'unconnected' user: 'root' host: `localhost' (Got an error writing communication packets) 000929 15:31:15 /usr/local/mysql/bin/mysqld: Normal shutdown 000929 15:31:15 /usr/local/mysql/bin/mysqld: Shutdown Complete 000929 15:31:54 mysqld started /usr/sbin/mysqld: ready for connections 22

MySQL backup methods SQL-level backup (logical backup) mysqldump Backup table files directly (physical backup) BACKUP TABLE mysqlhotcopy Other OSS tools Using LVM snapshots Setting up replication Commercial backup tools 23

mysqldump mysqldump dumps the table structure and data into SQL statements, which can be saved in files $ mysqldump mydb > mydb.20050925.sql You can dump individual tables or whole databases The default output from mysqldump consists of SQL statements, CREATE TABLE statements for table structure and INSERT statements for the data mysqldump can also be used directly as input into another mysqld server (without creating any files) $ mysqldump opt world mysql hwork.mysql.com world 24

Recovering With Backups Recovered database = Backup files + binary log In order to restore the tables to the state before a crash you will need both your backup files and the binary log From the backup files you can restore the tables to the state they were at the time of the backup From your synchronised binary logs you can extract the queries issued between the backup and now Beware, if you are recovering data lost due to unwise queries remember not to issue them again 25

Example SQL level restore Restore the last full backup mysql < backup.sql apply all incremental changes done after the last full backup mysqlbinlog hostname bin.000001 mysql 26

MySQL table files backup Also called physical backup Database files can be simply be copied after issuing FLUSH TABLES WITH READ LOCK; The mysqlhotcopy Perl script automates this process (MyISAM table files only) Locking all tables for consistency can be expensive, if the file backup operation takes a long time 27

mysqlhotcopy mysqlhotcopy is a Perl script with which you can easily backup databases It can only be run on the same machine as where the databases are It does the following LOCK TABLES FLUSH TABLES Copies the table files to the desired location with cp or scp UNLOCK TABLES The user has to have write access to the target directory 28

Backing Up InnoDB Databases You can use the mysqldump single transaction tool to make an on-line backup To take a binary backup, do the following: 1. Shutdown the MySQL server 2. Copy your data files, InnoDB log files,.frm files and my.cnf file(s) to a safe location 3. Restart the server It is a good idea to backup with mysqldump also, since an error might occur in a binary file without you noticing it 29

OSS backup tools The usual suspects: cp, tar, cpio, gzip, zip called in a shell script via a cron job Use rsync or unison for bandwidthfriendly remote backups Complete network-based backup solutions like afbackup, Amanda or Bacula provide more sophisticated features (e.g. catalogs) 30

Linux backup support LVM snapshots DRBD ( RAID1 over the network ) Distributed file systems GFS Lustre 31

Backup using LVM snapshots Linux LVM snapshots provide a very convenient and fast backup solution for backing up entire databases without disruption The snapshot volume does not need to be very large (10-15% are sufficient in a typical scenario) A backup of the files from the snapshot volume can be performed with any tool 32

Linux LVM snapshot creation Basic principle: mysql> FLUSH TABLES WITH READ LOCK $ lvcreate -s -size=<size> --name=backup <LV> mysql> UNLOCK TABLES $ mount /dev/<vg>/backup /mnt $ tar czvf backup.tar.gz /mnt/* $ umount /mnt $ lvremove /dev/<vg>/backup 33

MySQL replication backing up a replication slave is less time-critical (the master is not blocked for updates) Keep the limitations of MySQL replication in mind make sure to back up the master.info and relay-log.info files as well as any SQL_LOAD-* files (if LOAD DATA INFILE is replicated) 34

Commercial backup solutions Acronis True Image ARCServe Arkeia InnoDB HotBackup SEP sesam Veritas vxfs snapshots 35

Backup Method Comparison The output from mysqldump is portable to any other DBMS (without the opt option) whereas the copied files only work with MySQL The file copying methods are much faster than mysqldump So it comes down to your preferences: Which tool do you prefer to use Speed vs. portability 36

Backup Principles Perform backups regularly Turn on the binary update log The update logs are needed to restore the database without losing any data Synchronise your update log files with your backup files Use FLUSH LOGS Name your backups consistently and understandably Include the date in the file name mydb.20050925.sql Store your backups on a different file system than where your databases are Backup your backup files with file system backups 37

General backup notes Putting the binary logs on a different file system (or even a different drive) than the data directory is recommended (increases performance and avoids data loss) Make sure the backup is consistent and complete! Define backup schedules and policies as well as recovery procedures Test that these actually work! 38

Thank you! Questions, Comments? Lenz Grimmer <lenz@mysql.com> 39