如何使用printf打印unsigned long long类型整数

使用%ull 即可

以前在网上搜找到的是直接用%lld就行了,但实际上如果遇到要打印的unsigned long long大于 long long的上限的话,printf打印出来的结果将不是预期的

=。=今天打acm遇到一道题刚好就被这里卡了,用lld输出过不了,llu就行

specifiers
length d i u o x X f F e E g G a A c s p n
(none) int unsigned int double int char* void* int*
hh signed char unsigned char signed char*
h short int unsigned short int short int*
l long int unsigned long int wint_t wchar_t* long int*
ll long long int unsigned long long int long long int*
j intmax_t uintmax_t intmax_t*
z size_t size_t size_t*
t ptrdiff_t ptrdiff_t ptrdiff_t*
L long double

*上表来自cpp Reference

 

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: 如何使用printf打印unsigned long long类型整数

使用mysqlbinlog恢复数据库(记一次作死的酒后打码)

最近做了个小项目:weloop小黑3表盘分享平台(https://www.iweloop.com),收到不少好评与点赞,表盘上传数、访问量日渐增加,发的帖子还被官方置顶了,成就感满满的~~

然而,作死的是,我在喝了几两白酒后竟然跑去敲了个新功能,并且没经过仔细测试就部署到生产环境了,导致所有数据遭到污染(update表时忘记加where),所有表盘名字作者丢失,罪过,罪过

b5fd6074ff2b135

虽然每日都有备份数据,但那时是晚上11点,恢复昨日备份意味着今日数据全部丢失。幸好想起mysql还有binlog这玩意,赶紧拿出来研究了一番。binlog是将每次对数据操作都记录下来,所以通过它就能非常方便地恢复数据,通过mysqlbinlog这个可执行程序就能将日记导出为sql执行语句

root@debian-1gb-sfo2-01:/usr/local/mysql/bin# ./mysqlbinlog
./mysqlbinlog Ver 3.3 for Linux at x86_64
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Dumps a MySQL binary log in a format usable for viewing or for piping to
the mysql command line client.

Usage: ./mysqlbinlog [options] log-files
-?, –help Display this help and exit.
–base64-output[=name]
Determine when the output statements should be
base64-encoded BINLOG statements: ‘never’ disables it and
works only for binlogs without row-based events;
‘decode-rows’ decodes row events into commented SQL
statements if the –verbose option is also given; ‘auto’
prints base64 only when necessary (i.e., for row-based
events and format description events); ‘always’ prints
base64 whenever possible. ‘always’ is deprecated, will be
removed in a future version, and should not be used in a
production system. –base64-output with no ‘name’
argument is equivalent to –base64-output=always and is
also deprecated. If no –base64-output[=name] option is
given at all, the default is ‘auto’.
–character-sets-dir=name
Directory for character set files.
-d, –database=name List entries for just this database (local log only).
–debug-check Check memory and open file usage at exit .
–debug-info Print some debug info at exit.
–default-auth=name Default authentication client-side plugin to use.
-D, –disable-log-bin
Disable binary log. This is useful, if you enabled
–to-last-log and are sending the output to the same
MySQL server. This way you could avoid an endless loop.
You would also like to use it when restoring after a
crash to avoid duplication of the statements you already
have. NOTE: you will need a SUPER privilege to use this
option.
-F, –force-if-open Force if binlog was not closed properly.
(Defaults to on; use –skip-force-if-open to disable.)
-f, –force-read Force reading unknown binlog events.
-H, –hexdump Augment output with hexadecimal and ASCII event dump.
-h, –host=name Get the binlog from server.
-l, –local-load=name
Prepare local temporary files for LOAD DATA INFILE in the
specified directory.
-o, –offset=# Skip the first N entries.
-p, –password[=name]
Password to connect to remote server.
–plugin-dir=name Directory for client-side plugins.
-P, –port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
–protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-R, –read-from-remote-server
Read binary logs from a MySQL server.
-r, –result-file=name
Direct output to a given file.
–server-id=# Extract only binlog entries created by the server having
the given id.
–set-charset=name Add ‘SET NAMES character_set’ to the output.
-s, –short-form Just show regular queries: no extra info and no row-based
events. This is for testing only, and should not be used
in production systems. If you want to suppress
base64-output, consider using –base64-output=never
instead.
-S, –socket=name The socket file to use for connection.
–start-datetime=name
Start reading the binlog at first event having a datetime
equal or posterior to the argument; the argument must be
a date and time in the local time zone, in any format
accepted by the MySQL server for DATETIME and TIMESTAMP
types, for example: 2004-12-25 11:25:56 (you should
probably use quotes for your shell to set it properly).
-j, –start-position=#
Start reading the binlog at position N. Applies to the
first binlog passed on the command line.
–stop-datetime=name
Stop reading the binlog at first event having a datetime
equal or posterior to the argument; the argument must be
a date and time in the local time zone, in any format
accepted by the MySQL server for DATETIME and TIMESTAMP
types, for example: 2004-12-25 11:25:56 (you should
probably use quotes for your shell to set it properly).
–stop-position=# Stop reading the binlog at position N. Applies to the
last binlog passed on the command line.
-t, –to-last-log Requires -R. Will not stop at the end of the requested
binlog but rather continue printing until the end of the
last binlog of the MySQL server. If you send the output
to the same MySQL server, that may lead to an endless
loop.
-u, –user=name Connect to the remote server as username.
-v, –verbose Reconstruct SQL statements out of row events. -v -v adds
comments on column data types.
-V, –version Print version and exit.
–open-files-limit=#
Used to reserve file descriptors for use by this program.

Variables (–variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
——————————— —————————————-
base64-output (No default value)
character-sets-dir (No default value)
database (No default value)
debug-check FALSE
debug-info FALSE
default-auth (No default value)
disable-log-bin FALSE
force-if-open TRUE
force-read FALSE
hexdump FALSE
host (No default value)
local-load (No default value)
offset 0
plugin-dir (No default value)
port 3306
read-from-remote-server FALSE
server-id 0
set-charset (No default value)
short-form FALSE
socket /tmp/mysql.sock
start-datetime (No default value)
start-position 4
stop-datetime (No default value)
stop-position 18446744073709551615
to-last-log FALSE
user root
open-files-limit 64

具体几个实用的配置选项:

-d, –database=name 指定查询日记中的数据库名字

#下面几个可以选用几个使用,未必一定要同时指定开始和结束位置

–start-datetime 指定要提取的日记开始时间 如2004-12-25 11:25:56

–stop-datetime=name 指定要提取的日记停止时间

-j, –start-position= 指定要提取的日记开始的位置(位置需加引号)

–stop-position= 指定要提取的日记结束的位置(位置需加引号)

实践:

首先切换到mysql数据库日记目录,如我的是/usr/local/mysql/var

然后找到要修复的数据库的日记文件

root@debian-1gb-sfo2-01:/usr/local/mysql/var# ../bin/mysqlbinlog --database=weloop_watchface ./mysql-bin00006 | more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;

确定数据未被污染的位置

root@debian-1gb-sfo2-01:/home/mysqlbinlog# /usr/local/mysql/bin/mysqlbinlog --database=weloop_watchface mysql-bin.000006 | tac  | grep -C 7 "update watchface set" | more
SET TIMESTAMP=1484921355/*!*/;
#170120 22:09:15 server id 1  end_log_pos 7232064 	Query	thread_id=101969	exec_time=0	
error_code=0
# at 7231984
COMMIT/*!*/;
#170120 22:09:15 server id 1  end_log_pos 7231984 	Xid = 305468
# at 7231957
/*!*/;
update watchface set wf_name='7hours_金馆长大宝剑动态表盘',maker_name='thxsechee'
SET TIMESTAMP=1484921355/*!*/;
#170120 22:09:15 server id 1  end_log_pos 7231957 	Query	thread_id=101969	exec_time=0	
error_code=0
# at 7231791
/*!*/;
BEGIN
SET TIMESTAMP=1484921355/*!*/;
#170120 22:09:15 server id 1  end_log_pos 7231791 	Query	thread_id=101969	exec_time=0	
error_code=0
--
SET TIMESTAMP=1484579327/*!*/;
#170116 23:08:47 server id 1  end_log_pos 116716 	Query	thread_id=943	exec_time=0	error_co
de=0
# at 116636
COMMIT/*!*/;
#170116 23:08:17 server id 1  end_log_pos 116636 	Xid = 5210

由于以上数据倒着输出,所以最后正确数据操作位置是在7231791,导出数据

root@debian-1gb-sfo2-01:/home/mysqlbinlog# /usr/local/mysql/bin/mysqlbinlog --database=weloop_watchface --stop-position="7231791" mysql-bin.000006 > oplog.sql

然后找台机子,安装mysql,直接导入oplog.sql即可得到那个时间点前的数据库,再把被污染的数据表导出来,覆盖生产环境的数据表即可

 

教训:

1、勤做备份,并保证备份数据安全与可用,并掌握通过备份数据快速恢复的方法,不然做了备份也是白搭(@炉石)

2、上线新功能时一定一定要有一个清醒的头脑

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: 使用mysqlbinlog恢复数据库(记一次作死的酒后打码)

screenCloser–一个一键快捷关闭屏幕的小程序

正如程序名称,这个程序只有一个功能,关闭显示器。

网上找了一圈,没发现有能一键关闭屏幕的软件,于是动手写了个

运行一秒钟后会自动关闭显示器,方便笔记本电脑用户。

建议右键 固定到任务栏 ,效果如图

 

 

aaaaa

 

 

下载地址:screenCloser

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: screenCloser–一个一键快捷关闭屏幕的小程序

php foreach 遍历bug:最后两个元素重复

网上找了找,貌似2007里就有的bug,现在还没修复。

在用键值做引索的数组里使用foreach遍历就会出现最后两个元素重复的bug。

有两种解决方法:

1、不使用键值做引索

2、遍历时使用引用来遍历(此乃本人无意中发现)

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: php foreach 遍历bug:最后两个元素重复

极路由opkg安装插件到SD卡上

根据openwrt上的方法http://wiki.openwrt.org/doc/techref/opkg 外加自己的一些折腾,实现了安装软件包到SD卡上。没办法,/overlay的空间实在太小了,装不了几个插件

首先,用df查看你的SD卡挂载到的地方,我的是

/tmp/storage/mmcblk0p2/

我打算将软件包安装到SD卡下的system目录内,先新建一个system的文件夹

首先需要修改opkg的几个文件,分别是/etc/opkg.conf 与/etc/opkg.d/opkg-fast.conf 在里面加上

dest usb /tmp/storage/mmcblk0p2/system

当然了,挂载点要改成你的。
改完之后,还需要对系统的环境变量进行修改,不然安装包后会出现找不到库的情况。
文件位于/etc/profile 这个文件是用来加载环境变量的
打开编辑,在export PATH=这一行的最后面加上

:/tmp/storage/mmcblk0p2/system/bin:/tmp/storage/mmcblk0p2/system/sbin:/tmp/storage/mmcblk0p2/system/usr/bin:/tmp/storage/mmcblk0p2/system/usr/sbin

当然了,挂载点要改成你的。
还有export LD_LIBRARY_PATH=这一行最后面

:/tmp/storage/mmcblk0p2/system/lib:/tmp/storage/mmcblk0p2/system/usr/lib

当然了,挂载点要改成你的。
修改完成后保存
输入

source /etc/profile

重新载入此文件
到这里就完事了。需要安装插件到sd卡时,opkg要加上参数-d usb

root@Hiwifi:/etc/opkg.d# opkg remove  transmission-daemon
Removing package transmission-daemon from usb...
root@Hiwifi:/etc/opkg.d# opkg install transmission-daemon transmission-web -d usb
Installing transmission-daemon (2.71-1) to usb...
Downloading http://downloads.openwrt.org.cn/PandoraBox/ralink/mt7620/packages/transmission-daemon_2.71-1_ralink.ipk.
Installing transmission-web (2.71-1) to usb...
Downloading http://downloads.openwrt.org.cn/PandoraBox/ralink/mt7620/packages/transmission-web_2.71-1_ralink.ipk.
Configuring transmission-daemon.
Configuring transmission-web.

原创文章,转载请注明: 转载自YXZ’s Blog

本文链接地址: 极路由opkg安装插件到SD卡上