Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Involuntary DBA Where there is Linux, you most likely will find MySQL or MariaDB. Like it or not, if you're working with Linux, you're a DBA.

Similar presentations


Presentation on theme: "The Involuntary DBA Where there is Linux, you most likely will find MySQL or MariaDB. Like it or not, if you're working with Linux, you're a DBA."— Presentation transcript:

1 The Involuntary DBA Where there is Linux, you most likely will find MySQL or MariaDB. Like it or not, if you're working with Linux, you're a DBA.

2 Installation Use your distro's package manager (e.g. apt or yum)
Download .mariadb.org/ Current GA Versions MySQL Community Server MariaDB MySQL or MariaDB is probably already running and being used for something in your network, but if you're asked to install it, you may have to decide between the two. MySQL and MariaDB are basically the same. MariaDB is just the MySQL founder Monty Widenius's response to Oracle's acquisition and perceived closing of the open source. If you want Oracle's support, use MySQL. If you want features that Oracle is allegedly withholding from the Community, use MariaDB. You can also pay SkySQL for support of MariaDB. To install either, just use the package manager for you favorite Linux distro. Then you'll be able to keep your binaries up-to-date. The current GA version of MySQL is and of MariaDB is

3 Resetting the root password
The SQL UPDATE mysql.user SET Password = PASSWORD('blah') WHERE User='root'; FLUSH PRIVILEGES; Running the SQL on startup # ./mysqld_safe --init-file=/home/root/mysql/reset_mysql_root_password.sql & If you've stumbled on a rogue installation of MySQL or MariaDB, you probably won't be able to log in, at least not with enough privileges to properly maintain and configure the system. Assuming you have OS access to stop and start the mysql service, stop the service. Then save the SQL above to a file, and invoke the file when starting the service manually with 'mysqld_safe'. Be sure that the user under which 'mysqld' is running has access to this file. Once you've verified that you can log in as root, restart the service normally. You can use this technique with any account, but the idea is that 'root' has the all important 'WITH GRANT OPTION' needed to create and change other accounts.

4 What's Where Binaries /usr/sbin/mysld /usr/bin/mysql
/usr/bin/mysqld_safe Start up /init.d/mysql/mysql.server Configuration /etc/mysql/my.cnf Data files /var/lib/mysql Log files /var/log/mysql One way or another, MySQL or MariaDB is installed. Here's a basic guide to where the package manager put things by default. From the DBA's point of view, there's no need to touch the binaries or the start-up scripts. You will want to spend some time modifying 'my.cnf', however. In that file you can change the location of the data files and log files, possibly putting them on different storage subsystems for optimal performance. By default, all logs and data live in '/var/lib/mysql'. First enable the error log and put it in '/var/log/mysql'.You will also want to enable transaction logs and put them there as well.

5 Configuration - Memory
Allocate as much memory as possible Boost innodb_buffer_pool and for InnoDB innodb_buffer_pool_size= up to 80% of RAM Boost key_buffer_size for MyISAM if used SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE FROM information_schema.tables WHERE TABLE_SCHEMA <> 'mysql' AND ENGINE = 'MyISAM'; key_buffer_size= up to 25% of a RAM Although they can be changed dynamically, most critical MySQL configuration parameters persists in the file 'my.cnf'. On startup the daemon looks for this file in '/etc/' and then '/etc/mysql/'. Given the default configuration, there are a few parameters, you should tweak. First, give the database as much memory as you can by setting 'innodb_buffer_pool_size', if you're using the InnoDB storage engine, and 'key_buffer_size', if you're using the MyISAM storage engine. By default MySQL uses InnoDB for all new tables. The query above will tell you where you're using MyISAM if at all.

6 Configuration – Storage
Logs and Data datadir = /var/log/mysql innodb_log_file_size = lesser of 50% of innodb_buffer_pool_size or 1GB Manage logs for loading Turn off binary (transaction) logging by commenting out log location # log_bin = /var/log/mysql/mysql-bin.log Manage logs for durability (point-in-time restore) Turn on binary logging by uncommenting log location and restarting. log_bin = /var/log/mysql/mysql-bin.log expire_logs_day=2 Move undo logs to disk subsystem that's different from the one for data files innodb_log_group_home_dir = /var/log/mysql/ Enable error logging log_error=/var/log/mysql/error.log After memory, the specification of logs and data files has the greatest impact on performance and durability. You can use 'datadir' to put data files on the fastest disk subsystem available. Assuming you're using InnoDB, specify 'innodb_log_file_size' as half the memory allocated to the innodb buffer pool up to 1GB. The larger the file the longer mysql can go without writing data to the data files, thereby reducing disk IO contention. To further reduce disk IO contention during initial database loads, turn off transaction logging by commenting out or omitting 'log_bin' which specifies the location of the transaction logs, called 'binary' logs in MySQL. Once the load is complete, re-enable logging so that the database can be rolled forward to a point in time after the last full backup. If backups run nightly, you can set these logs to expire after a minimum of two days (expire_logs_days=2). Ideally, these logs are stored on a set of disks different from the ones that contain your data. Similarly, you may want to move your InnoDB log file to a set of disks different from the ones that contain your data, using 'innodb_log_group_home_dir'. Finally, remember to enable error logging with 'log_error'.

7 Backups Create a database user for backups
GRANT SELECT, RELOAD, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW, TRIGGER ON *.* TO IDENTIFIED BY PASSWORD('blah'); Use mysqldump with --master-data=2 and --single- transaction mysqldump -u backup -pblah --master-data=2 -- single-transaction --all-databases --log- error=mysqldump_error.log > mysqldump.sql Create bash script that runs 'mysqldump' Add line that copies 'mysqldump.sql' and new transaction logs off-site log_bin = /var/log/mysql/mysql-bin.log Schedule cron job to run the script at least daily Using your 'root' account create a user that has the privileges needed to perform full backups. Then create a 'bash' script that executes the command 'mysqldump' with the credentials added. Other important parameters are 'master-data=2', which will add the co-ordinates of the binary (transaction) log at the time of the backup and 'single-transaction', which will dump all InnoDB tables in a state consistent with coordinates of the binary log. Assuming you're using InnoDB, this command will produce a backup that you can use with binary logs to roll forward to a point in time. Ideally, add to this bash script a line that copies the resulting backup and binary logs specified by 'log_bin' to another system preferably at another data center for DR. Then create a cron job to run the script at least daily.

8 Monitoring Create database use for monitoring
GRANT PROCESS, REPLICATION CLIENT ON *.* TO IDENTIFIED BY PASSWORD('blah'); Use cron with 'mysqladmin' to monitor connections mysqladmin -u monitor -pblah ping mysqld is alive mysqladmin -u monitor -pblah status Uptime: 32 Threads: 1 Questions: 1 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.031 mysqladmin -u monitor -pblah variable | grep max_connections | max_connections | 100 If ping != “mysqld is alive” or (Threads/max_connections)*100 > 75, then send an alert Use Nagios or something comparable if you have it Monitor the usual suspects, like disk space, CPU usage and memory usage on the system running MySQL Using your 'root' account create a user that has the privileges needed to monitor server status. Then create a bash script that runs 'mysqladmin' with various arguments and evaluates the output. Based on that output, send alerts. The key metrics to monitor are whether or not 'mysqld' is running and whether or not threads connected is within 75% of the the maximum number of connections that database allows. The latter check will also verify connectivity. Any monitoring system, such as Nagios, Hyperic or Zabbix, can implement these checks and alerts and many, many more. Ganglia is also usefull graphing performance over time.

9 Now You Know the Basics Installation Configuration
A little user access control Backups Monitoring Both MySQL and MariaDB documentation is excellent /mariadb-documentation/


Download ppt "The Involuntary DBA Where there is Linux, you most likely will find MySQL or MariaDB. Like it or not, if you're working with Linux, you're a DBA."

Similar presentations


Ads by Google