➜ ~ docker run -itd --name docker-mysql-master -v /Users/chenyuan/Data/docker/mysql-data-master:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -p 33061:3306 mysql 88820868af121cbac02f48a8c8e5c9eae5c6cf7241eefd3646634e14526a940f ➜ ~ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 88820868af12 mysql "docker-entrypoint.s…" About a minute ago Up About a minute 33060/tcp, 0.0.0.0:33061->3306/tcp docker-mysql-master ➜ ~ docker exec -it 88820868af12 bash root@88820868af12:/# root@88820868af12:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
➜ ~ docker commit -a "chengcheng222e@sina.com" -m "created by vernon" 88820868af12 mysql-versnon:v1 sha256:e9691f399c321ea221b48e6142e9501f0ee69964fa4be687ac189f8444d75d66 ➜ ~ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql-versnon v1 e9691f399c32 13 seconds ago 456MB mysql latest d435eee2caa5 3 weeks ago 456MB
# MySQL RUNcd ~/tools/ RUN yum -y install numactl RUN yum -y install libaio RUN yum -y install pwgen RUN yum install -y perl-Data-Dumper RUN tar -zxvf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz RUNmv mysql-5.6.45-linux-glibc2.12-x86_64 /usr/local/mysql RUN groupadd mysql RUN useradd -g mysql mysql RUNchown -R mysql /usr/local/mysql RUNchgrp -R mysql /usr/local/mysql
show variables like 'binlog_format' set globle binlog_format='MIXED' show variables like 'log_bin' show binary logs
遇到问题:
1 2 3 4 5 6 7 8 9 10 11
[mysql@c738746e9623 support-files]$ ./mysql.server start Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/c738746e9623.pid).
// 表示事务4641对表`sys`.`new_table`持有了IX锁 TABLE LOCK table `sys`.`new_table` trx id 4641 lock mode IX // space id=38,space id可以唯一确定一张表,表示了锁所在的表 // page no 3,表示锁所在的页号 // index PRIMARY 表示锁位于名为PRIMARY的索引上 // lock_mode X locks rec but not gap 表示x record lock // 下方的数据表示了被锁定的索引数据,最上面一行代表索引列的十六进制值,在这里表示的就是id=3的数据 RECORD LOCKS space id 38 page no 3 n bits 80 index PRIMARY of table `sys`.`new_table` trx id 4641 lock_mode X locks rec but not gap Record lock, heap no 4 PHYSICAL RECORD: n_fields 8; compact format; info bits 0 0: len 4; hex 00000003; asc ;; 1: len 6; hex 0000000011e9; asc ;; 2: len 7; hex a70000011b0128; asc (;; 3: len 4; hex 8000012c; asc ,;; 4: len 1; hex 63; asc c;; 5: len 4; hex 80000006; asc ;; 6: len 3; hex 636363; asc ccc;; 7: len 2; hex 3333; asc 33;; // lock_mode X表示的是next-key lock,即当前记录的record lock+前一个间隙的gap lock // 这个锁在名为idx1的索引上,对应的索引列的值为100(hex 64对应十进制),对应聚簇索引的值为1 RECORD LOCKS space id 38 page no 5 n bits 80 index idx1 of table `sys`.`new_table` trx id 4643 lock_mode X Record lock, heap no 2 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 00000064; asc d;; 1: len 4; hex 00000001; asc ;; // lock_mode X locks gap before rec表示的是对应索引记录前一个间隙的gap lock RECORD LOCKS space id 38 page no 5 n bits 80 index idx1 of table `sys`.`new_table` trx id 4643 lock_mode X locks gap before rec Record lock, heap no 3 PHYSICAL RECORD: n_fields 2; compact format; info bits 0 0: len 4; hex 800000c8; asc ;; 1: len 4; hex 00000002; asc ;;
死锁日志解析:
lock_mode X locks rec but not gap:模式排它锁,类型行锁;
lock_mode X locks gap before rec :模式排它锁,类型gap锁;
lock_mode X locks gap before rec insert intention:模式排它锁,类型插入意向锁;
# Master INSERT INTO test.person_01 (id, first_name, age, gender) VALUES (10, 'chenyuan', 20, 'M'); # Slave INSERT INTO test.person_01 (id, first_name, age, gender) VALUES (11, 'chenyuan11', 20, 'M'); # 2边数据一致就OK mysql>select*from person_01; +------+------------+------+--------+ | id | first_name | age | gender | +------+------------+------+--------+ |1| Bob |25| M | |2| Jane |20| F | |3| Jack |30| M | |4| Bill |32| M | |5| Nick |22| M | |6| Kathy |18| F | |7| Steve |36| M | |8| Anne |25| F | |1| Vernon |300| M | |10| chenyuan |20| M | |11| chenyuan11 |20| M | +------+------------+------+--------+ 11rowsinset (0.00 sec)
[root@a40a40c6bde7 mysql]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1 link/ipip 0.0.0.0 brd 0.0.0.0 3: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1 link/tunnel6 :: brd :: 21: eth0@if22: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever inet 172.17.0.99/32 scope global eth0 valid_lft forever preferred_lft forever
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@a579aa381425 support-files]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1 link/ipip 0.0.0.0 brd 0.0.0.0 3: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1 link/tunnel6 :: brd :: 23: eth0@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0 valid_lft forever preferred_lft forever
由此可见,现在172.17.0.99/32`是在master节点上。
验证
通过docker-mysql-client机器来登录数据库,下面显示登录成功。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@8f31266d08fc bin]# ./mysql -h 172.17.0.99-u root -p Enter password: Welcome to the MySQL monitor. Commands endwith ; or \g. Your MySQL connection id is173 Server version: 5.6.45-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
mysql>show variables like'server_id'; ERROR 2013 (HY000): Lost connection to MySQL server during query mysql>show variables like'server_id'; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 62 Current database: ***NONE***
我们的目的就是,在JVM运行中的时候,将process()方法做替换,在其前后分别打印“start”和“end”。也就是在运行中时,每五秒打印的内容由”process”变为打印”start process end”。那如何解决JVM不允许运行时重加载类信息的问题呢?为了达到这个目的,我们接下来一一来介绍需要借助的Java类库。
Mac 在国外很受欢迎,尤其是在 设计/web开发/IT 人员圈子里。普通用户喜欢 Mac 可以理解,毕竟 Mac 设计美观,简单好用,没有病毒。那么为什么专业人士也对 Mac 情有独钟呢?从个人使用经验来看我想有下面几个原因:
1、Mac OS X 是基于 Unix 的。这一点太重要了,尤其是对开发人员,至少对于我来说很重要,这意味着Unix 下一堆好用的工具都可以随手捡到。如果你是个 windows 开发人员,我想你会在 windows 上装一套cygwin 环境吧?你不用 flex/yacc,grep,screen,ssh,make?好多 open source 的项目只提供cygwin/gcc/make 的编译环境。Mac 就是基于 BSD Unix 的,所有这些都是 built in 的。
2、开发环境。c/c++/java/perl/python/php/ruby/lisp,各种 shell,应有尽有,直接支持,非常方便。你要在 windows 上开发 C++,要装个 Visual Studio 编译器吧?或者其他的 C++ 编译器;你要开发 Java,你要下载 Java SDK 吧,说不定还要一个 Elipse 或者 Netbean;你要用 Perl,要安装一个 Perl 解释器吧,Active Perl?你要 python/php/ruby,你要安装……?开发程序需要库,图像处理,视频处理,人工智能之类大部分库都是只支持 Unix/Linux 的。Mac 基于 Unix,所以这些通通都和 Mac 能很好和睦相处。
3、编辑器 Vi/Emac。作为 程序员/IT 人员一个好用的编辑器太重要了,因为写程序/改系统配置都需要编辑器。我在 Mac 上差不多1/2的时间是 browser/email,另外1/2时间差不多就是 Vi 了。
4、没有病毒/木马。用了5年多的 Mac 就没看到病毒长成什么样,我还看不到 Mac 上装杀毒软件的需要。
6、简洁。Mac 上所有的操作都简洁到了极致,尽量避免干扰用户,增加了程序员的生产力。比如切换无线网功能,在 Mac 上切换只需要1次鼠标点击就可以完成,在 windows 上需要点击多次鼠标(包括一些很愚蠢的确认对话框);再比如卸载 USB 盘,Mac 只需要1次鼠标点击,windows 至少需要点击右下角图标、停止设备、确认对话框等多次点击。
8、程序员文化。国外程序员是以 Unix 为主流成长起来的。这一点和国内不同,中国程序员/开发人员大都是从90年代的 DOS 开始的,随着 Windows 的壮大,成长了一批使用 Microsoft 工具的程序员。这也解释了为什么自从 Mac 切换到 Unix 阵营后,Mac 会发展这么快。基于 Unix 的 Mac 一经推出后,迅速赢得了一大批老 Unix hacker 和新 Web 2.0/Linux hacker 的关注,正是因为这些忠实的 fans 影响了他们的人际网络,圈子,博客,从而影响了整个程序员文化。有点像 Ruby on Rails,开始是一小部分人(精英人士)试用,这些人感觉不错就在博客,研讨会等各种场合鼓吹,从而在 Web 开发领域刮起一阵 Ruby 风。
9、苹果很酷。每台电脑,每个系列都设计完美,从包装盒,宣传册,广告,电源线,电脑内部,电脑外观,电脑软件都精心设计,风格统一。甚至微小到螺丝,看过苹果机箱上的螺丝,机箱里面的数据线吗?那个也是设计。每个 Mac 上都标记着:Designed by Apple in California,而不是 Desgined in USA,苹果就是这么酷,“我们是一家加州公司”。苹果的保密措施可以说做到了极致,产品官方不发售就在市场上看不到踪影。
10、企业家精神。苹果的传奇经历吸引了大批硅谷创业者,Apple/Google/Microsoft/Amazon/eBay/Yahoo 代表了创新,进取的企业家精神。这不是一个大原因,但可以看作是 Mac 在国外,尤其是在美国,尤其是在硅谷,尤其是在大学这么流行的一个小原因吧。据调查2007年美国大学 Mac 市场占有率第一,这些大学精英们毕业以后走上工作岗位,走上社会,再过几年其中一部分走入中层,走进高层,他们会如何影响 Mac 呢?
/** * An informative annotation type used to indicate that an interface * type declaration is intended to be a <i>functional interface</i> as * defined by the Java Language Specification. * * Conceptually, a functional interface has exactly one abstract * method. Since {@linkplain java.lang.reflect.Method#isDefault() * default methods} have an implementation, they are not abstract. If * an interface declares an abstract method overriding one of the * public methods of {@code java.lang.Object}, that also does * <em>not</em> count toward the interface's abstract method count * since any implementation of the interface will have an * implementation from {@code java.lang.Object} or elsewhere. * * <p>Note that instances of functional interfaces can be created with * lambda expressions, method references, or constructor references. * * <p>If a type is annotated with this annotation type, compilers are * required to generate an error message unless: * * <ul> * <li> The type is an interface type and not an annotation type, enum, or class. * <li> The annotated type satisfies the requirements of a functional interface. * </ul> * * <p>However, the compiler will treat any interface meeting the * definition of a functional interface as a functional interface * regardless of whether or not a {@code FunctionalInterface} * annotation is present on the interface declaration. * * @jls 4.3.2. The Class Object * @jls 9.8 Functional Interfaces * @jls 9.4.3 Interface Method Body * @since 1.8 */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public@interface FunctionalInterface {}
/** * Represents an operation that accepts a single input argument and returns no * result. Unlike most other functional interfaces, {@code Consumer} is expected * to operate via side-effects. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #accept(Object)}. * * @param <T> the type of the input to the operation * * @since 1.8 */ @FunctionalInterface publicinterfaceConsumer<T> {
/** * Performs this operation on the given argument. * * @param t the input argument */ voidaccept(T t);
/** * Returns a composed {@code Consumer} that performs, in sequence, this * operation followed by the {@code after} operation. If performing either * operation throws an exception, it is relayed to the caller of the * composed operation. If performing this operation throws an exception, * the {@code after} operation will not be performed. * * @param after the operation to perform after this operation * @return a composed {@code Consumer} that performs in sequence this * operation followed by the {@code after} operation * @throws NullPointerException if {@code after} is null */ default Consumer<T> andThen(Consumer<? super T> after) { Objects.requireNonNull(after); return (T t) -> { accept(t); after.accept(t); }; } }
/** * Represents a supplier of results. * * <p>There is no requirement that a new or distinct result be returned each * time the supplier is invoked. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #get()}. * * @param <T> the type of results supplied by this supplier * * @since 1.8 */ @FunctionalInterface publicinterfaceSupplier<T> {
/** * Gets a result. * * @return a result */ T get(); }
首先此接口只有一个抽象方法get,该方法不接收参数,返回一个T类型的结果。
定义使用类
1 2 3
publicstatic <T> T doSupplier(Supplier<T> supplier) { return supplier.get(); }
/** * Represents a predicate (boolean-valued function) of one argument. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #test(Object)}. * * @param <T> the type of the input to the predicate * * @since 1.8 */ @FunctionalInterface publicinterfacePredicate<T> {
/** * Evaluates this predicate on the given argument. * * @param t the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ booleantest(T t);
/** * Returns a composed predicate that represents a short-circuiting logical * AND of this predicate and another. When evaluating the composed * predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param other a predicate that will be logically-ANDed with this * predicate * @return a composed predicate that represents the short-circuiting logical * AND of this predicate and the {@code other} predicate * @throws NullPointerException if other is null */ default Predicate<T> and(Predicate<? super T> other) { Objects.requireNonNull(other); return (t) -> test(t) && other.test(t); } }
/** * Represents a function that accepts one argument and produces a result. * * <p>This is a <a href="package-summary.html">functional interface</a> * whose functional method is {@link #apply(Object)}. * * @param <T> the type of the input to the function * @param <R> the type of the result of the function * * @since 1.8 */ @FunctionalInterface publicinterfaceFunction<T, R> {
/** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ R apply(T t);
/** * Returns a composed function that first applies the {@code before} * function to its input, and then applies this function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of input to the {@code before} function, and to the * composed function * @param before the function to apply before this function is applied * @return a composed function that first applies the {@code before} * function and then applies this function * @throws NullPointerException if before is null * * @see #andThen(Function) */ default <V> Function<V, R> compose(Function<? super V, ? extends T> before) { Objects.requireNonNull(before); return (V v) -> apply(before.apply(v)); }
/** * Returns a composed function that first applies this function to * its input, and then applies the {@code after} function to the result. * If evaluation of either function throws an exception, it is relayed to * the caller of the composed function. * * @param <V> the type of output of the {@code after} function, and of the * composed function * @param after the function to apply after this function is applied * @return a composed function that first applies this function and then * applies the {@code after} function * @throws NullPointerException if after is null * * @see #compose(Function) */ default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) { Objects.requireNonNull(after); return (T t) -> after.apply(apply(t)); }
/** * Returns a function that always returns its input argument. * * @param <T> the type of the input and output objects to the function * @return a function that always returns its input argument */ static <T> Function<T, T> identity() { return t -> t; } }