Wednesday, June 1, 2016

Responsibilities of MySQL DBA


MySQL DBA Responsibilities
Overview of DBA duties
  • Server startup/shutdown
  • Mastering the mysqladmin administrative client
  • Using the mysql interactive client
  • User account maintenance
  • Log file maintenance
  • Database backup/copying
  • Hardware tuning
  • Multiple server setups
  • Software updates and upgrades
  • File system security
  • Server security
  • Repair and maintenance
  • Crash recovery
  • Preventive maintenance
  • Understanding the mysqld server daemon
  • Performance analysis
Obtaining and Installing MySQL
  • Choosing what else to install (e.g. Apache, Perl +modules, PHP)
  • Which version of MySQL (stable, developer, source, binary)
  • Creating a user acccount for the mysql user and group
  • Download and unpack a distribution
  • Compile source code and install (or rpm)
  • Initialize the data directory and grant tables with mysql_install_db
  • Starting the server
  • Installing Perl DBI support
  • Installing PHP
  • Installing Apache
  • Obtaining and installing the samp_db sample database
The MySQL Data Directory
  • deciding/finding the Data Directory’s location
  • Structure of the Data Directory
  • How mysqld provides access to data
  • Running multiple servers on a single Data Directory
  • Database representation
  • Table representation (form, data and index files)
  • OS constraints on DB and table names
  • Data Directory structure and performance, resources, security
  • MySQL status files (.pid, .err, .log, etc)
  • Relocating Data Directory contents
Starting Up and Shutting Down the MySQL Server
  • Securing a new MySQL installlation
  • Running mysqld as an unprivileged user
  • Methods of starting the server
  • Invoking mysqld directly
  • Invoking safe_mysqld
  • Invoking mysql.server
  • Specifying startup options
  • Checking tables at startup
  • Shutting down the server
  • Regaining control of the server if you can’t connect
Managing MySQL User Accounts
  • Creating new users and granting privileges
  • Determining who can connect from where
  • Who should have what privileges?
  • Administrator privileges
  • Revoking privileges
  • Removing users
Maintaining MySQL Log Files
  • The general log
  • The update log
  • Rotating logs
  • Backing up logs
Backing Up, Copying, and Recovering MySQL Databases
  • Methods: mysqldump vs. direct copying
  • Backup policies
  • Scheduled cycles
  • Update logging
  • Consistent and comprehensible file-naming
  • Backing up the backup files
  • Off-site / off-system backups
  • Backing up an entire database with mysqldump
  • Compressed backup files
  • Backing up individual tables
  • Using mysqldump to transfer databases to another server
  • mysqldump options (flush-logs, lock-tables, quick, opt)
  • Direct copying methods
  • Database replication (live and off-line copying)
  • Recovering an entire database
  • Recovering grant tables
  • Recovering from mysqldump vs. tar/cpio files
  • Using update logs to replay post-backup queries
  • Editing update logs to avoid replaying erroneous queries
  • Recovering individual tables
Tuning the MySQL Server
  • Default parameters
  • The mysqladmin variables command
  • Setting variables (command line and options file)
  • Commonly used variables in performance tuning
  • back_log
  • delayed_queue_size
  • flush_time
  • key_buffer_size
  • max_allowed_packet
  • max_connections
  • table_cache
  • Erroneous use of record_buffer and sort_buffer
Running Multiple MySQL Servers
  • For test purposes
  • To overcome OS limits on per-process file descriptors
  • Separate servers for individual customers (e.g. ISPs)
  • Configuring and installing separate servers
  • Procedures for starting up multiple servers
Updating MySQL
  • Stable vs. development releases
  • Updates for both streams
  • Using the “Change Notes”
  • Bug fixing vs. new features
  • Dependencies on the MySQL C client library (PHP, Apache, Perl DBD::mysql)
MySQL Security
  • Assessing risks and threats
  • Internal security: data and directory access
  • Access to database files and log files
  • Securing both read and write access
  • Filesystem permissions
  • External security: network access
  • Structure and content of the MySQL Grant Tables.
  • user, db, host, tables_priv, columns_priv.
  • Grant table scope fields/columns.
  • Grant table privilege columns.
  • Database and table privileges: ALTER, CREATE, DELETE, DROP, INDEX, INSERT, SELECT, UPDATE.
  • Administrative privileges: FILE, GRANT, PROCESS, RELOAD, SHUTDOWN.
  • Server control over client access: matching grant table entries to client connection requests and queries.
  • Scope column values: Host, User, Password, Db, Table_name, Column_name.
  • Query access verification.
  • Scope column mmatching order.
  • Grant table risks: the FILE and ALTER privileges.
  • Setting up users without GRANT.
  • The anonymous user and sort order.
MySQL Database Maintenance and Repair
  • Checking and repairing tables.
  • Invoking myisamchk and isamchk.
  • Extended checks.
  • Standard table repair.
  • Table repair with missing/damaged index or table description.
  • Avoid server-checking interaction, without shutdowns.

Thursday, March 12, 2015

Maria DB Replication - Master Slave.

Maria DB Replication.
Configuring the master
  1. Enable binary logging if it's not already enabled.
  2. Give the master a unique server_id. All slaves will also be given a server_id. This can be a number from 1 to 232-1, and must be unique for each server in the replicating group.
  3.  Slaves will need permission to connect and start replicating from a server. Usually this is done by creating a dedicated slave user, and granting that user permission only to replicate (REPLICATION SLAVE permission).

Example

In your my.cnf file.

log-basename=master
log-bin=/var/log/mariadb/mariadb-bin
binlog-format=row
server_id=1


 Execute in the SQL prompt:
GRANT REPLICATION SLAVE ON *.* TO replication_user;
Variables to check                                           
There are a number of options that may impact or break replication. Check the following variable settings to avoid problems.
·         Skip-networking. If skip-networking=1, the server will limit connections to localhost only, and prevent all remote slaves from connecting.
·         bind_address. Similarly, if the address the server listens for TCP/IP connections is 127.0.0.1 (localhost), remote slaves connections will fail.
Configuring the slave                             
        Give the slave a unique server_id. All servers, whether masters or slaves, are given a server_id. This can be a number from 1 to 232-1, and must be unique for each server in the replicating group. The server will need to be restarted in order for a change in this option to take effect.

Getting the master's binary log co-ordinates
  1. Now you need prevent any changes to the data while you view the binary log position. You'll use this to tell the slave at exactly which point it should start replicating from.

On the master, flush and lock all tables by running.           
FLUSH TABLES WITH READ LOCK;

Keeps this session running - exiting it will release the lock.

      2.  Get the current position in the binary log by running SHOW MASTER STATUS; 

SHOW MASTER STATUS;
+--------------------+----------+--------------+--------------------------+
| File                         | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+--------------------------+
| mariadb-bin.000096 |      568 |                       |                           |
+--------------------+----------+--------------+--------------------------+         

Record the File and Position details. If binary logging has just been enabled, these will be blank.
·         Now, with the lock still in place, copy the data from the master to the slave.
·         Once the data has been copied, you can release the lock on the master by running UNLOCK TABLES.

                                                  UNLOCK TABLES;
 Start the Slave
      Once the data has been imported, you are ready to start replicating. Begin by running a CHANGE MASTER TO, making sure that MASTER_LOG_FILE matches the file and MASTER_LOG_POS the position returned by the earlier SHOW MASTER STATUS.

Ex:

CHANGE MASTER TO
  MASTER_HOST='192.168.1.110',
  MASTER_USER='replication_user',
  MASTER_PASSWORD='Coffee$123#',
  MASTER_PORT=3306,
  MASTER_LOG_FILE='mariadb-bin.020496',
  MASTER_LOG_POS=4987,
  MASTER_CONNECT_RETRY=10;


        Now start the slave with the START SLAVE command.

   START SLAVE;


Tuesday, March 10, 2015

Upgrading MySQL Server.

Follow the below steps to upgrade MySQL Server to a newer version.
  1. First take the backup of all databases in the present MySQL Server.
  2. Remove the MySQL Server Installed in the server.
  3. Download the new RPM/Binary Packages from http://www.mysql.com/downloads
  4. Install the packages in the Server.
  5. Give the permissions to the server i.e., /var/lib/mysql folder.
  6. Run mysql_upgrade
  7. Now Restore the databases on the server.
  8. Now check the server whether all the database tables have been on the server.