Blue Whale platform MySQL database management practices recommendations

Blue Whale platform MySQL database management practices recommendationsMySQL as the primary database platform data access blue whale, blue whale, which is related to the stability of the platform experience, and its data security may related to enterprise IT asset information, should be in the process of installing and maintaining the blue whale platform adequate attention. This paper will analyze and provide treatment recommendations as there have been a few problems. These questions are: upgrade, configure log automatic cleaning, binlog manual cleaning and maintenance, clear the table, backup.

Blue whale platform MySQL database is automatically installed when the platform, which version 5.5.24, copied from the main framework (5 servers), the following are some of the mentioned problems is described.

MySQL Upgrade

1. Analysis

Blue Whale platform MySQL version is 5.5.24 installed by default, generally do not meet the safety requirements of the scanned version, in order to avoid use due to security concerns need to upgrade the database, the database upgrade is recommended in a timely manner after the completion of the platform installation, then database no business data stored in the highest version, upgrade risk-free and high-efficiency upgrade, based on already proven in the build environment upgrade experience, in order to prevent release span is too large due to compatibility problems, we recommend upgrading to MySQL5.5 namely 5.5.62 , logical method to upgrade, use mysqldump low version of the database full database export, then imported into the new version installed.

2. Logical upgrade process

1, check the current MySQL process

Check the details of the currently running MySQL process, mainly to see the startup parameters for comparison after the upgrade

[root@paas-1 install]# ps -ef |grep mysql

root 20407 8526 0 15:10 pts/3 00:00:00 grep --color=auto mysql

root 29942 1 0 Dec17 ? 00:00:00 /bin/sh /data/bkce/service/mysql/bin/mysqld_safe --datadir=/data/bkce/public/mysql/ --pid-file=/data/bkce/public/mysql/mysql.pid

mysql 30344 29942 5 Dec17 ? 13:17:37 /data/bkce/service/mysql/bin/mysqld --basedir=/data/bkce/service/mysql --datadir=/data/bkce/public/mysql/ --plugin-dir=/data/bkce/service/mysql/lib/plugin --user=mysql --log-error=/data/bkce/public/mysql//paas-1.err --pid-file=/data/bkce/public/mysql/mysql.pid --socket=/data/bkce/logs/mysql/mysql.sock --port=3306

2, full backup

Using the following command full backup, the backup path can be adjusted according to the amount of data, disk performance, etc.

[root@paas-1 service]# mysqldump -uroot -x -A -E -R >/tmp/alldbback.sql

3. Backup installation directory, data directory

Stop the database service, and basedir, datadir directory backup, be sure to make a backup before upgrading, to avoid accidental rollback

[root@paas-1 service]# mkdir /data/backup

[root@paas-1 service]# mv mysql/ /data/backup/

[root@paas-1 service]# cd /data/bkce/public/

[root@paas-1 public]# mv mysql /data/backup/mysql_data

4, the new version extract the installation

Decompress using binary packages to install, download the 5.5.62 version of the archive, upload it to decompress the installation directory, create a soft link to mysql

[root@paas-1 service]# tar zxf /tmp/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz

[root@paas-1 service]# ln -s mysql-5.5.62-linux-glibc2.12-x86_64/ mysql

5, initialize the database

Initialize the data directory

[root@paas-1 public]# mkdir mysql

[root@paas-1 mysql]# cd /data/bkce/service/mysql

[root@paas-1 mysql]# ./s/mysql_install_db --user=mysql --basedir=/data/bkce/service/mysql --datadir=/data/bkce/public/mysql/

Installing MySQL system tables...

181227 15:39:10 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

181227 15:39:10 [Note] /data/bkce/service/mysql/bin/mysqld (mysqld 5.5.62-log) starting as process 24766 ...

OK

Filling help tables...

181227 15:39:11 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.

181227 15:39:11 [Note] /data/bkce/service/mysql/bin/mysqld (mysqld 5.5.62-log) starting as process 24790 ...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/data/bkce/service/mysql/bin/mysqladmin -u root password 'new-password'

/data/bkce/service/mysql/bin/mysqladmin -u root -h 132.108.252.43 password 'new-password'

Alternatively you can run:

/data/bkce/service/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /data/bkce/service/mysql ; /data/bkce/service/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /data/bkce/service/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

6, modify the configuration and startup

My.cnf because the original profile is not set up pid file will be automatically generated when a new version of the boot according to the host name does not match with the pid file under the original process, you need to add the following configuration in the configuration file:

pid-files=

vim /etc/my.cnf

[mysqld]

/data/bkce/public/mysql/mysql.pid

Start the database:

/data/bkce/service/mysql/bin/mysqld_safe &

7, import data

Log mysql, confirmation has been upgraded to version 5.5.62, then import the backup data

mysql -uroot </tmp/alldbback.sql

Wait for it to complete the import.

8, file recovery mysql.sh

Start or stop the mysql service on the Blue Whale platform machine control is done by calling mysql.sh file in the installation directory, so you need to restore the file to the directory after installing a new version

[root@paas-1 mysql]# cd /data/backup/mysql/bin/

[root@paas-1 bin]# cp mysql.sh /data/bkce/service/mysql/bin/

9. Upgrade Confirmation

View by Control Unit Commitment mysql, check whether it is normal

[root@paas-1 mysql]# cd /data/install/

[root@paas-1 install]# ./bkcec status mysql

[root@paas-1 install]#./bkcec stop mysql

[root@paas-1 install]#./bkcec start mysql

[root@paas-1 install]# ps -ef |grep mysql

Check the blue whale platform, database calls to see whether it is normal. This, the entire upgrade process is completed.

MySQL Configuration

1. Analysis

I have dealt with the problem of blue whales MySQL platform, many because of insufficient disk space cause, and disk space is mostly due to excessive binlog log cleared up without cause, the blue whale at the customer using the process because there is no specific operation and maintenance team usually with little to focus on back-end servers, so the automatic cleaning mechanism binlog strongly recommended that you turn.

2. test procedure

1, set up automatic cleanup binlog

Parameter expire_logs_days indicates exceeds the parameter value binlog log automatic cleanup may be determined set the value according to the server disk space, the premise is to ensure that the log retention time of greater than database backup frequency, such as backup seven days a full backup, the expire_logs_days value should be greater than 7, the case where sufficient space is generally recommended to 7 days, or 15 days.

A method is provided, in the configuration parameter file expire_logs_days = 7 to take effect after a restart MySQL. It can also be set directly in the MySQL command line:

mysql> set global expire_logs_days=7;

Setting does not immediately clean up the log at the command line, you need to achieve the following several trigger conditions:

1, binlog size exceeds max_binlog_size

2, performed manually flush logs

When 3, MySQL service is restarted

So if MySQL is the process of using the command line to set the parameters, you can use the flush logs log trigger switch to clean up, then you need to pay attention to clean up the need to take up server I / O resources, should be implemented without affecting the use case.

binlog manual cleaning and maintenance

1. Analysis

When the disk space binlog due to lack of space, MySQL services have been suspended, you need to manually clean up binlog log. The problem is that a few times treated administrator deleted all binlog log in cleaning binlog, after the release of disk space, restart the MySQL service discovery failed to start, the reason is to clean up after all the binlog is, MySQL service start date needs to be written to the log a binlog, and the last binlog can not find their records, so the error will fail to start.

1, the right way to manually clean up

When manual cleaning binlog log, need to retain a new log to ensure that the database is restarted can detect the latest written to the log, confirm the last log, according to the log name (incremented) or write time to determine.

2, delete all the logs after treatment

If you have deleted all the log database can not be started at this time can be handled as follows:

Find mysql-bin.index file in the datadir directory, the file is recorded in the database binlog information, empty the contents of the file, restart the database, then the log will be reset to No. 1, the database back to normal.

Empty operating table

1. Analysis

Because some log database table too large, affecting the efficiency of queries and inserted into the table, and sometimes will do the operation to clear the table, while administrators maintain MySQL database used to using graphical tools such as Navicat, when the data table is relatively large, from graphics click empty tool table, the system will be stuck, because the tool table in the case of a delete operation, the database will be executed for each data record for deletion and redo, undo logs, database hang occupy a large database of resources due to live.

1, the right way to empty the table

If the confirmation form data is not needed, use the truncate table situation the way, very high efficiency and small footprint, SQL syntax is as follows:

mysql> truncate table_name;

MySQL Backup

1. Analysis

The most important thing is the database data, data security above all else, and complete security of data backup is the last line of defense, Blue Whale platform is an enterprise-class platform for its data storage is crucial, so the backup strategy must rational development. The most common MySQL backup backup mysqldump into logical, physical backup xtrabackup, when the amount of data, backup can be completed in 1 hour using mysqldump to larger amount of data is required to consider xtrabackup, the following describes mysqldump.

2. Backup versatility command

mysqldump is a very flexible tool, there are many parameters can be used in the backup, but backup for mysql blue whale platform recommended by generic backup command:

mysqldump -uroot -p --all-databases --master-data=2 --flush-logs --single-transaction > /backup/dbfull-date +%F.sql

If you need to compress the backup files, you can use the following command:

mysqldump -uroot -p --all-databases --master-data=2 --flush-logs --single-transaction |gzip > dbfull-date +%F.tar.gz

The command to back up all databases, record binlog position (the starting point for establishing a master-slave relationship, or copy recovery points to a specified time), transactional way back up, does not affect the main run-time library backups.

If you are a local disk backup, backup files also need regular cleaning, such as cleaning up the backup file 30 days before the clean-up script can refer to the following:

find /backup -mtime +30 -name "dbfull-*.sql" -exec rm -rf {} \;

With the widespread use of blue whales in the enterprise-class platform, MySQL database to store its data should ensure data security and MySQL services running smoothly, several issues listed herein are the common cause of the problem can not use the platform, its processing methods embodiment are verified and generating the environment of use, such problems can be treated as the reference.

Guess you like

Origin blog.51cto.com/11811406/2401023