create databasename Create a new database 新建数据库 debug Instruct server to write debug information to log 把 debug 日志记录到日志文件中 drop databasename Delete a database and all its tables 删除数据库 extended-status Gives an extended status message from the server 查看 MySQL 服务器的状态信息 flush-hosts Flush all cached hosts flush-logs Flush all logs flush-status Clear status variables flush-tables Flush all tables flush-threads Flush the thread cache flush-privileges Reload grant tables (same as reload) kill id,id,... Kill mysql threads password [new-password] Change old password to new-password in current format ping Check if mysqld is alive processlist Show list of active threads in server reload Reload grant tables refresh Flush all tables and close and open logfiles shutdown Take server down status Gives a short status message from the server start-slave Start slave stop-slave Stop slave variables Prints variables available version Get version info from server
举例:
1 2
zj@bogon:/usr/local/mysql/bin$ mysqladmin -uroot -p shutdown Enter password:
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 [sudo] password for zj: /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup
......
create table test2(id int,name varchar(30)) /*!*/; # at 1366 #170920 20:50:29 server id 1 end_log_pos 1431 CRC32 0x18a95938 Anonymous_GTID last_committed=6 sequence_number=7 SET @@SESSION.GTID_NEXT= 'ANONYMOUS'/*!*/; # at 1431 #170920 20:50:29 server id 1 end_log_pos 1509 CRC32 0x2fa8bd6c Query thread_id=4 exec_time=0 error_code=0 SET TIMESTAMP=1505911829/*!*/; BEGIN /*!*/; # at 1509 #170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0 SET TIMESTAMP=1505911829/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
加 -d 选项,将只显示 t2 数据库的操作日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -d t2 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
......
SET TIMESTAMP=1505911829/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; # at 4 #170920 20:44:49 server id 1 end_log_pos 123 CRC32 0x42fd5a4d Start: binlog v 4, server v 5.7.18-log created 170920 20:44:49 at startup # Warning: this binlog is either in use or was not closed properly. ROLLBACK/*!*/; BINLOG ' wWLCWQ8BAAAAdwAAAHsAAAABAAQANS43LjE4LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAADBYsJZEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA AU1a/UI= '/*!*/; # at 1509 #170920 20:50:29 server id 1 end_log_pos 1622 CRC32 0x77ce6f3b Query thread_id=4 exec_time=0 error_code=0 use `t2`/*!*/; SET TIMESTAMP=1505911829/*!*/; SET @@session.pseudo_thread_id=4/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1436549152/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8mb4 *//*!*/; SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; insert into test2 select * from t1.test1 /*!*/; # at 1622 #170920 20:50:29 server id 1 end_log_pos 1653 CRC32 0x41b7a45b Xid = 29 COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
加 -r 选项,将上面的结果输出到文件 resultfile 中
1 2 3 4 5
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -r ./logfile zj@bogon:/usr/local/mysql/bin$ sudo more ./logfile /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; ...
zj@bogon:/usr/local/mysql/bin$ sudo ./mysqlbinlog --no-defaults /data/mysql/mysql-bin.000001 -o 20 -s /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; use `t2`/*!*/; SET TIMESTAMP=1505911829/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1436549152/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8mb4 *//*!*/; SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; insert into test2 select * from t1.test1 /*!*/; COMMIT/*!*/; SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/; DELIMITER ; # End of log file /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
root@bogon:/usr/local/mysql/bin# more ./bak/emp.sql -- MySQL dump 10.13 Distrib 5.7.18, for Linux (x86_64) -- -- Host: localhost Database: t2 -- ------------------------------------------------------ -- Server version 5.7.18-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-- -- Table structure for table `emp` --
DROP TABLE IF EXISTS `emp`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `emp` ( `id` int(11) NOT NULL DEFAULT '0', `name` varchar(10) DEFAULT NULL, `context` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2017-09-21 12:07:38
1 2 3
root@bogon:/usr/local/mysql/bin# more ./bak/emp.txt 1 a a 2 b b
zj@bogon:/usr/local/mysql/bin$ perror 30 OS error code 30: Read-only file system zj@bogon:/usr/local/mysql/bin$ perror 60 OS error code 60: Device not a stream zj@bogon:/usr/local/mysql/bin$ perror 30 60 OS error code 30: Read-only file system OS error code 60: Device not a stream