mysql-advanced article, classification and function of mysql log, backup and recovery of mysq database~~~!

Change secret~

change Password

  • Operation outside the database
  • method-1
mysqladmin -uroot password 新密码
    • method-2
mysqladmin -uroot  -p旧密码  password 新密码
  • Operation in the database
  • method-1
set  password  for  root@’loalhost’=password(123);
    • method-2
update mysql.user set Password=password(‘新密码’) where User=’用户名’  and Host=’主机’;

flush privileges; Refresh library

reset Password

step

  1. service myslqd stop Close the database [centos6 command]
    mysqld_safe --skip-grant-tables skip the authorization list
  2. Open another terminal directly, type on the command line to mysqllog in to the database
  3. update mysql.user set Password=password('123') where User='root' and Host='localhost'; Change the database user table
    flush privileges; refresh library
  4. service mysqld restart Restart mysql

database backup

  • [The actual backup is the mysql statement]

Commands used:

mysqldump , Is a shell command

Can add parameters:

-u "用户"   -p "密码"  -A 全部备份  -B "指定DB"
-c "压缩"   -T "指定表"  -o "指定目录"  -t "指定并行数,默认是4"
-P 端口  -q:快速导出 -d:只导出表结构 -X:导出为xml文件
-f:即使发现sql错误,仍然继续备份  
--less-locking "尽量减少锁表锁定时间(针对InnoDB)"

-A parameter example:

mysqldump -uroot -proot  -A > all.sql 

-B parameter example:

mysql -uroot -proot -B wg > wg.sql
  • Export method-1
mysql -uroot -proot < wg.sql 
    • Export method-2
source /root/wg.sql 

Backup a table of the specified database

mysqldump -uroot -proot  mysql  user > user.sql
 数据库名 表名>盘符:\路径\文件名.sql

Recovery table

  • Import the user table into the wg database
mysql -uroot -proot wg < user.sql

Create user

create user 用户名@'地址' identified by'密码';

Steps:

  • Client side executes native ip101
create user tom@’192.168.1.102
  • Server side executes native ip102
mysql -utom -h192.168.101

The accelerated operation of mysql:

  • skip_name_resolve[Skip domain name resolution]
  • Add in the configuration file, restart to take effect

Authority

  • Common permissions include:
  • create drop insert select update delete .....
- all:对指定的库拥有全部权限

- select:只有查看指定库的权限

- insert:只有在指定库的插入记录权限

- update:updtae(字段1,字段2.......)更新权限,对某表某字段的更改权限

- delete- USAGE:对库和表没有任何权限,用户只能登录

- 多个权限逗号,分隔:select,insert.

[Among them, only selectthe permission is read, the others are the permission of write]

  • (View permission)
show  grants  for tom@’192.168.1.102;

Scope of action:

  • 【Global Library List】
  • Database name
*.*    全局级别 所有数据库和所有表
库.*   库级别 指定库的所有表
库.表  表级别 指定库的指定表

Grant of authority

grant  create,drop  on  *.*  to  tom@’192.168.1.102; 
  • analysis
grant    权限     on  数据库名.表名 to 用户@'地址';【字段解析】   

  • Example:
    to authorize the creation and deletion permissions for the tom user of the 192.168.1.101 host
 grant create,drop on *.* to tom@'192.168.1.101';

Revocation of authority

  • Withdraw the creation permission of Jack user
revoke  create   on  wg.stu from jack@’192.168.1.102;
  • analysis
revoke 权限列表 on 数据库名.表名 from 用户@'地址';

Log:

----- View mysqlthe running status

Error log

Record mysqlproblems that occur when starting, running or stopping

    • Troubleshooting command [view log]:
tail -f  /var/log/mysql.log 

Status---

warning 警告  note 笔记  error 出错

Query log

general log(General log), misunderstanding that it is only selectfor query,
in fact update, sometimes it will be queried because it is very likely to update a certain piece of data during the update
delete, and only delete the data that meets the conditions.

  • In scenarios where there are a lot of concurrent operations, there will be a lot of query information, so if they are recorded, it will cause very large IO and affect MySQL performance. Therefore, if it is not in a debugging environment, it is not recommended to enable the query log function.

Slow log:

Record long query time logs,
show variables like ‘ %char%’; coded character set fuzzy query

  • step:
编辑配置文件   vim  /etc/my.cnf 
开启慢日志     log_slow_queries=1 
指定慢日志路径 slow_query_log_file=/tmp/mysql.slow.log

Binary log

Our records add, delete, change the mysqlstatement

  • Edit configuration file
   vim  /etc/my.cnf 
添加 log_bin=mysql-bin   
 (放路径 /var/lib/mysql)
  • Query/View Binary Log
show  variables  like  ‘ %log_bin%;
  • Check location【position】Change
show master status; 
  • mysql-bin.000001| mysql -uroot binary log recovery database [location]
 mysqlbinlog  /var/lib/mysql/mysql-bin.000001
mysqlbinlog  --start-position=106  --stop-position=185
  • mysql-bin.000001| mysql -uroot binary log recovery database [time]
mysqlbinlog  --start-datetime=2020-06-17 15:46:30--start-datetime=2020-06-17 15:46:56’
  命令         开始位置            结束位置

Reset binary log: all binary log files will be deleted and restored to the original state

Relay log

  • relay logIt is the log generated during the replication process. It is binary logsimilar in many aspects . The difference is: relay logthe slave library server I/O thread reads the binary log of the main library server and records it to the local file of the slave library server, and then the SQL thread of the slave library will Read relay-logthe content of the log and apply it to the slave library server

Guess you like

Origin blog.csdn.net/qing1912/article/details/109015824