mysql integrity of the backup and backup considerations

mysql integrity of the backup and backup considerations

 
describe user; // see table
describe mysql.user // describe can be abbreviated as desc
the Create databese abc; // create a database
show databases; equivalent to / var / lib / mysql / there will be a folder, of course, this can also be directly inside create a library such as cloud, the show databases; you can see in to. The only difference is that rights are not the same. It is a is a root MySQL.
Use to switch to the library ABC //
Create Table Users (USER_NAME char (18 is) Not null, user_passwd char (48) default '', Primary Key (USER_NAME));
Show Tables;
drop Table Users;
drop ABC Database;
---------------------------------
INSERT INTO table name (field 1, field 2, ... ) value vlaues (field 1, field 2, .....) is inserted into the table value //
insert users (user_name, user_passwd) values ( 'zhangsan', '123456') // insert data INTO
iNSERT INTO Users (user_name, user_passwd) values ( ' zhang', passwd'123456 ') // encrypted storage
---------------------------------
the SELECT * from the Users; // Display * for all table
select user_name from users ; // view data for a column
SELECT USER_NAME, user_password from Users;
SELECT * WHERE USER_NAME = from Users 'zhangsan';
desc mysql.user
select Host,User,Password from mysql.user;
select Host,User,Password from mysql.user where Host='127.0.0.1';  //条件查询
----------------------------------
update users set user_passwd=passwd('654321') where user_name='zhangsan';
 select * from users;
-----------------------------------
use mysql
select user,password from usser;
update user set password=password('123123') where user='root';
select user,password from user;
flush privileges;
-----------------------------------
delete from users where user_name='zhaosi';
----------------------------------------
case:. Grant select on abc * to ' teacher '@' localhost 'identified by ' 123456 ';
use the grant statement authorized user records will be saved to the user mysql database, db, host, tables_priv other related tables without authorization correspondence table to take effect.
==============================
common backup method
mysqldump (backup tools)
----------- ------------------
MySQL log species
error log
binary log (common)
relay logs
query log
slow query log (SQL performance optimization)
transaction log
-----------------
Percona XtraBackup (Mysql hot backup software )
------------------------
thinking kind of problem:
the total amount of corporate databases ranks how much?
Increase the amount of daily how much?
Backup strategy?
The amount of data backed up?
When backing up long?
----------------------------------
MySQL Full operation
Source installation position / usr / local / MySQL / Data
RPM package installation position / var / lib / mariadb /
Open Service:
systemctl Start MariaDB
mysqladmin -u 123456 -pssword the root
into the analog data database
MySQL -uroot--p123456
Create the auth Database ;
use the auth;
Create User Table (name char (10) Not null, ID int (48));
INSERT INTO User values ( 'crushlinux', '123');
SELECT * from User;
----
the above data backup
is first stop library
systemctl STOP MariaDB
LS / var / lib / MySQL / // rub nice auth
packing compression
rpm -q xz // xz is the most common
yum -y install the xz
mkdir backup
tar JCF backup / mysql_all - $ (DATE + F.%) .tar.xz / var / lib / MySQL /
LS -l Backup /
 Analog data loss
delete auth
RM -rf / var / lib / MySQL / auth /
LS / var / lib / MySQL /
systemctl Start MariaDB
MySQL-uroot--p123456
Show Databases;
 ---------
recover data
mkdir Restore
tar xf backup / mysql _..... -C restore /
then view
mv auth / / var / lib / mysql
and view them in a database
==================== ====
using mysqldump backup (common)
mysql have this tool that comes with
all of this tool will export the data into mysql sql script, when you need to upgrade mysql server, you can use the mysqldump command to export the original library information, and then import it directly into the mysql server upgraded in
[1] to back up a single library
format: mysqldump -u username -p password [options] --databeses [database name]> / backup path / backup file name
musqldump -uroot - p123456 --databases auth> backup / auth - $ (date +% Y% m% d) .sql
grep -Ev "^ / | ^ $ | ^ -" backup / auth-2019..sql // View archive content
[2] of multiple libraries backup
format: mysqldump -u username -p password [options] --databeses library name 1 [library name 2] ...> / backup path / backup file name
musqldump -uroot -p123456 - -events --databases mysql auth> backup / mysql + auth - $ (date +% Y% m% d) .sql
[3] for a full backup of all libraries
formats: mysqldump -u username -p password [option] - opt --all-databases> / backup path name of the backup file
musqldump -uroot -p123456 --events --opt --all-databases > backup / mysql_all. $ (date +% Y% m% d) .sql
[4] for table full backup
format: mysqldump -u username -p password [options] database watches name> / backup path / file name of the backup
 mysqldump -uroot -p123456 auth user> backup / auth_user - $ (date +% Y% m% d ) .sql
[5] backup (interview) table structure
format: mysqldump -u username -p [password] -d database watches name> / backup path / file name of the backup
 mysqldump -uroot -p123456 -d mysql user> backup / desc_mysql_user - $ (DATE the Y% m%% + D) .sql
==============================
After using mysqldump backup, restore the database
1, source command to
log in to the MySQL database, execute the backup source path sql script
MySQL-uroot--p123456
Show Databases;
drop Database auth;
source Backup / mysql_all.20181214.sql
Show Databases;
2, MySQL command
format :
 mysql -u username -p [password] <backup path script
 mysql -u username -p [password] library name <path table backup script
mysql -uroot -p123456 -e 'show databases; /// - e may be performed directly statement
[the root @ localhost ~] # MySQL -uroot--p123456 -e 'Database drop the auth;'
[the root @ localhost ~] # MySQL -uroot--p123456 <Backup / mysql_all.20181214.sql
[the root @ localhost ~ ] # mysql -uroot -p123456 -e 'show databases;'
[the root @ localhost ~] # MySQL -uroot--p123456 -e 'drop Table auth.user;'
[the root @ localhost ~] # MySQL -uroot--p123456 the auth <Backup / AUTH_USER-20181214.sql
[the root @ localhost ~] # -uroot--p123456 -e MySQL 'SELECT * from auth.user;'
==============================
the MySQL backup ideas
1 regularly implement a backup, specify a backup plan or policy, and strictly adhere to
2, in addition to a full backup binlog log function, open the MySQL server is very important (a full backup plus a log, you can maximize the reduction of MySQL)
3, using unified and easy to understand the name of the backup, it is recommended to use the library name or table name plus the naming of time, such as mysql_user-20181214.sql, do not use backup1 like abc or no sense to name.
4, regular checks reliability of backups, such as doing a test restore to check the file size or other means.
5, to store backup data off-site or across a room, etc., to prevent damage to the source data and backup files together.
==============================
 
 
 
 

Guess you like

Origin www.cnblogs.com/elin989898/p/11961520.html