mysql8 window安装,链式复制,双主复制,数据库的负载均衡

2023-11-04

by xuejianxinokok@163.com    2021年3月25日 周四 15:06:43
====================================
1. 下载地址
https://dev.mysql.com/downloads/mysql/

 2. 下载文件名称为:  mysql-8.0.23-winx64.zip 到  
3. 安装准备

 

 4. 初始化种子库
 
4.1 在D:\soft\mysql\mysql8023\bin 目录下执行以下命令
 mysqld --initialize-insecure

4.2 执行成功后 生成数据目录
D:\soft\mysql\mysql8023\data

5. 创建服务

 创建 D:\soft\mysql\mysql8023\conf\my8023.conf   内容如下

------------------------------------------------------ --------------------------
[mysqld]
port=8023
default_authentication_plugin=mysql_native_password
basedir=D:/soft/mysql/mysql8023/soft
datadir=D:/soft/mysql/mysql8023/data/8023
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#复制用
server-id = 8023
log-bin = mysql-bin
    -----------------------------------------------------------------------------------
总体结构如下

安装服务 

mysqld --install mysql8023 --defaults-file="D:/soft/mysql/mysql8023/conf/my8023.conf"

 

 如果登录 会有以下错误

需要输入

D:\soft\mysql\mysql8023\soft\bin\mysql -P8023 -uroot
    执行如下sql
    alter user 'root'@'localhost' identified with mysql_native_password by '123456';
    update mysql.user set host='%' where user='root';
    flush privileges;

========================================================================
配置复制环境

停止mysql8023 服务

复制data/8023 目录 
其中 8024,8025,8026 为链式复制  8024=复制到=》8025=复制到=》8026
其中 8027,8028,8029 为双主复制  8027=复制到=》8029    8028=复制到=》8029 

 复制my8023.conf 为以下内容

 需要修改conf 文件中的端口和 data 路径 如下图所示

 删除服务
sc delete mysql8024
sc delete mysql8025
sc delete mysql8026
sc delete mysql8027
sc delete mysql8028
sc delete mysql8029
创建服务
mysqld --install mysql8024 --defaults-file="D:/soft/mysql/mysql8023/conf/my8024.conf"
mysqld --install mysql8025 --defaults-file="D:/soft/mysql/mysql8023/conf/my8025.conf"
mysqld --install mysql8026 --defaults-file="D:/soft/mysql/mysql8023/conf/my8026.conf"
mysqld --install mysql8027 --defaults-file="D:/soft/mysql/mysql8023/conf/my8027.conf"
mysqld --install mysql8028 --defaults-file="D:/soft/mysql/mysql8023/conf/my8028.conf"
mysqld --install mysql8029 --defaults-file="D:/soft/mysql/mysql8023/conf/my8029.conf"

把所有的服务有设置为手动

 -----------------------------------------------配置链式复制----------------------------------------

启动 8024,8025,8026 配置链式复制 8024=复制到=》8025=复制到=》8026

 

配置主库 8024
show master status;

获取日志文件坐标:(文件,便宜)
FILE: mysql-bin.000001
POSITON: 156


登录从库8025 执行
-- 停止复制
-- STOP REPLICA;

--配置复制  这里会弹出错误不需要理他,注意主库的ip 地址要正确

CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost',SOURCE_PORT=8024,SOURCE_USER='root',SOURCE_PASSWORD='123456',SOURCE_LOG_FILE='mysql-bin.000001',SOURCE_LOG_POS=156;


[注:,SOURCE_LOG_FILE='mysql-bin.000001',SOURCE_LOG_POS=156;要和主库上面SHOW MASTER STATUS,后复制红框中的值mysql-bin.000001  156的时候得到的值一致]

--开始复制
START REPLICA
--停止复制
-- STOP  REPLICA

--确认是否开始复制
在从库上执行
SHOW REPLICA STATUS

 结果为
Waiting for master to send event  说明复制成功

在主库8024上创建库

CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use test;
create table user (
id int primary key,
name varchar(50)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
;


insert into user values (1,'aName');

select * from user;


在从库8025 上确认

 由于 8025是复制库,所以有中级日志,如果没有配置relay_log 默认为  机器名-relay-bin

所以最好设置
#relay_log =/a/b/c/relay-bin 中继日志位置和名称
relay_log =relay-bin
#允许备库将其重放的时间也记录到自身的二进制文件中,默认的情况下mysql是关闭的
#从库做为其他从库的主库时 log-slave-updates参数是必须要添加的,因为从库要作为其他从库的主库,
#必须添加该参数。该参数就是为了让从库从主库复制数据时可以写入到binlog日志
#从库开启log-bin参数,如果直接往从库写数据,是可以记录log-bin日志的,但是从库通过I0线程读取主库二进制日志文件,
#然后通过SQL线程写入的数据,是不会记录binlog日志的。也就是说从库从主库上复制的数据,是不写入从库的binlog日志的。
#所以从库做为其他从库的主库时需要在配置文件中添加log-slave-updates参数
#该参数默认打开
log_slave_updates=1

#sync_binlog保证每次事物提交前会八二进制日志同步到磁盘,保证数据不丢失
sync_binlog=1


在 从库8026 上执行,注意8026 从8025 复制

CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost',SOURCE_PORT=8025,SOURCE_USER='root',SOURCE_PASSWORD='123456',SOURCE_LOG_FILE='mysql-bin.000001',SOURCE_LOG_POS=156;

START REPLICA

-- STOP  REPLICA

验证级联复制 

 -- 在8024 上插入,验证8025 和8026 是否存在
insert into user values (2,'xuejianxin');

-----------------------------------------------配置双主库复制----------------------------------------

启动 mysql8027,mysql8028,mysql8029

 8027上查询
SHOW MASTER STATUS 

 8028上查询
SHOW MASTER STATUS 

8029上执行

CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost',SOURCE_PORT=8027,SOURCE_USER='root',SOURCE_PASSWORD='123456',SOURCE_LOG_FILE='mysql-bin.000001',SOURCE_LOG_POS=156 for channel '8027';

START REPLICA for channel '8027';

CHANGE REPLICATION SOURCE TO SOURCE_HOST='localhost',SOURCE_PORT=8028,SOURCE_USER='root',SOURCE_PASSWORD='123456',SOURCE_LOG_FILE='mysql-bin.000001',SOURCE_LOG_POS=156 for channel '8028';

START REPLICA for channel '8028';


SHOW REPLICA STATUS


-- stop REPLICA for channel '8027';
-- stop REPLICA for channel '8028';

 在主库8027上创建库

CREATE DATABASE test8027 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use test8027;
create table user (
id int primary key,
name varchar(50)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
;


insert into user values (1,'aName');

select * from user;


在主库8028上创建库

CREATE DATABASE test8028 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
use test8028;
create table user (
id int primary key,
name varchar(50)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
;


insert into user values (1,'aName');

select * from user;


==============================mysqlrouter安装 负载均衡================================================
https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-installation.html 官方文档

解压 mysql-router-8.0.23-winx64.zip 到 mysqlrouter8023

全路径  D:\soft\mysql\mysqlrouter8023

sc delete MySQLRouter

D:\soft\mysql\mysqlrouter8023\bin\mysqlrouter.exe  --install-service  --config D:/soft/mysql/mysqlrouter8023/mysqlrouter.conf

配置文件内容
[DEFAULT]
base_dir = D:/soft/mysql/mysqlrouter8023

logging_folder={base_dir}/data/log
runtime_folder={base_dir}/data/run
data_folder   ={base_dir}/data/data
  
[logger]
#level = INFO
level = DEBUG

[routing:db1]
bind_address=0.0.0.0
bind_port=8020
destinations=127.0.0.1:8024
mode=read-write
client_connect_timeout=6
connect_timeout=3
max_connections=2048

[routing:db2]
bind_address=0.0.0.0
bind_port=8021
destinations=127.0.0.1:8025,127.0.0.1:8026
mode=read-only
client_connect_timeout=6
connect_timeout=3
max_connections=1024
 
------------------------------------------------------------------
测试负载均衡

D:\soft\mysql\mysql8023\soft\bin\mysql -P8020 -uroot -p123456 -e "use test; create table t1 (a int); insert into t1 values (1);"

第一次执行
D:\soft\mysql\mysql8023\soft\bin\mysql -P8021 -uroot -p123456 -e "show variables like 'server_id';select * from test.t1;"
第二次执行 
D:\soft\mysql\mysql8023\soft\bin\mysql -P8021 -uroot -p123456 -e "show variables like 'server_id';select * from test.t1;"

 ==============================nginx 负载均衡===============================================

配置文件路径 D:\soft\nginx\nginx-win32\conf


stream {
    upstream tcp8021 {
        hash $remote_addr consistent;   #负载方法
        server localhost:8025 max_fails=5 fail_timeout=30s;
        server localhost:8026 max_fails=5 fail_timeout=30s;
    }
    server {
        listen 8021;   
        proxy_connect_timeout 60;
        proxy_timeout 300s;    
        proxy_pass tcp8021;
   }
    server {
        listen 8021;   
        proxy_connect_timeout 60;
        proxy_timeout 300s;    
        proxy_pass tcp8021;
   }
}
 

==============================spring 多数动态据源负载均衡===============================================

参考 /bwiev2Admin/src/main/resources/config/applicationContext-datasource.xml 配置和实现

源码如下: com.common.spring.db.DynamicDataSource

public class DynamicDataSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        return DsHolder.get();
    }

}


3. 定义切面

<bean id="dataSourceAdvice" class="com.common.spring.db.DataSourceAdvice"></bean>
    <!-- 动态切换数据源  方法拦截器
    
             1. 注解形式切换数据源
               1.1此拦截器只会拦截以*DAO 结尾的类 
               1.2. 在DAO 中用以下方法切换,方法签名如下
               
                 @DataSource("read")
                 public List<TSSysUserinf> queryAllBybm();
             
               1.3. mapper 文件的写法没有变化
               1.4. 目前不支持分布式事务
               
             2. 如何用代码切换数据源:
                List<TSSysUserinf> result=DsHolder.execute("read", new IChangeDsCallback<List<TSSysUserinf>>() {
                    @Override
                    public List<TSSysUserinf> execute(String dsName) {
                            return service.queryByAll(params);
                    }
                } );
    -->
    <bean id="dataSourceAdviceBeanNameAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >
        <property name="proxyTargetClass" value="true"></property>
        <property name="beanNames" value="*Service,I*Service" />
        <property name="interceptorNames">
            <list>
                <value>dataSourceAdvice</value>
            </list>
        </property>
        <property name="order" value="99"/>
    </bean>

=====================================第三方库  ShardingSphere-JDBC,myCat 负载均衡======================================================

参考文档 https://shardingsphere.apache.org/document/current/cn/overview/#shardingsphere-proxy

https://dbaplus.cn/news-11-1854-1.html 对比总结,分析的很好
 

==============================jdbc 负载均衡================================================

支持复制的jdbc
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-source-replica-replication-connection.html
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-j2ee-concepts-managing-load-balanced-connections.html
https://blog.csdn.net/li_xiang_996/article/details/106195812

https://blog.51cto.com/xsunday/2049682  使用样例 
https://zhuanlan.zhihu.com/p/62279901  参数解释

1、readFromMasterWhenNoSlaves   readFromSourceWhenNoReplicas 当所有的salve死掉后,此参数用来控制主库是否参与读。如果从库的流量很大,配置此参数对主库有很大风险;但如果你关掉,请求则会快速失败。
2、loadBalanceStrategy 策略用来指定从库的轮询规则。有轮询,也有权重,也可以指定具体的策略实现。当你维护或者迁移某个实例时,先置空流量,这会非常有用。或许,你会给某DB一个预热的可能。
3、allowMasterDownConnections    allowSourceDownConnections如果主机当机,当连接池获取新的连接时,会失败。但如果打开此参数,则虚拟连接只会创建Slave连接组,整个连接会降级为只读,不论你设置了什么注解。
4、allowSlavesDownConnections   allowReplicasDownConnections=true如果没有只读库了,是否允许创建新的连接。在这种情况下,此参数开启,读操作有很大可能会失败。
5、retriesAllDown 当所有的hosts都无法连接时重试的最大次数(依次循环重试),默认为120。重试次数达到阈值仍然无法获取有效链接,将会抛出SQLException。
6、autoReconnect 实例既然有下线、就有上线。上线以后要能够继续服务,此参数用来控制断线情况下自动重连而不抛出异常。这会破坏事务的完整性,但还是默认开启。
Seamless Reconnection
Although not recommended, you can make the driver perform failovers without invalidating the active Statement or ResultSet instances by setting either the parameter autoReconnect or autoReconnectForPools to true. This allows the client to continue using the same object instances after a failover event, without taking any exceptional measures. This, however, may lead to unexpected results: for example, if the driver is connected to the primary host with read/write access mode and it fails-over to a secondary host in real-only mode, further attempts to issue data-changing queries will result in errors, and the client will not be aware of that. This limitation is particularly relevant when using data streaming: after the failover, the ResultSet looks to be alright, but the underlying connection may have changed already, and no backing cursor is available anymore.

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-source-replica-replication-connection.html  新参数配置

1. 添加jdbc
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.23</version>
</dependency>
 


Connector/J supports multi-source replication topographies.
The connection URL for replication discussed earlier (i.e., in the format of jdbc:mysql:replication://source,replica1,replica2,replica3/test) assumes that the first (and only the first) host is the source host. Supporting deployments with an arbitrary number of sources and replicas requires the "address-equals" URL syntax for multiple host connection discussed in Section 6.2, “Connection URL Syntax”, with the property type=[source|replica]; for example:
jdbc:mysql:replication://address=(type=source)(host=source1host),address=(type=source)(host=source2host),address=


    url  : jdbc:mysql:replication://localhost:8024,localhost:8025,localhost:8026,localhost:8024/test?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=false&failOverReadOnly=true&roundRobinLoadBalance=true&readFromSourceWhenNoReplicas=true&allowSourceDownConnections=true&allowReplicasDownConnections=true&retriesAllDown=3&connectionLifecycleInterceptors=com.app.common.core.MySqlConnectionLifecycleInterceptor


allowSourceDownConnections=true to allow Connection objects to be created even though no source hosts are reachable. Such Connection objects report they are read-only, and isSourceConnection() returns false for them. The Connection tests for available source hosts when Connection.setReadOnly(false) is called, throwing an SQLException if it cannot establish a connection to a source, or switching to a source connection if the host is available


 allowReplicasDownConnections=true to allow Connection objects to be created even though no replica hosts are reachable. A Connection then, at runtime, tests for available replica hosts when Connection.setReadOnly(true) is called (see explanation for the method below), throwing an SQLException if it cannot establish a connection to a replica, unless the property readFromSourceWhenNoReplicas is set to be “true” (see below for a description of the property)

重要:
 if you want to allow connection to a source when no replicas are available, set the property readFromSourceWhenNoReplicas to “true.” 
Notice that the source host will be used in read-only state in those cases, as if it is a replica host. Also notice that setting readFromSourceWhenNoReplicas=true might result in an extra load for the source host in a transparent manner.
readFromSourceWhenNoReplicas  需要把master 放到读库列表中,一般放到最后
协议的第一个连接,表示主库Master
后面的一堆连接,表示从库Slave,当然可以有多个
当你把Master的连接也放在后面的一堆里,那么它也拥有了“读库“的属性了

2. 测试方法
public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Properties props = new Properties();
        props.put("autoReconnect", "true");
        props.put("roundRobinLoadBalance", "true");
        props.put("user", "test");
        props.put("password", "123456");
        String url = "jdbc:mysql:replication://localhost:8024,localhost:8025,localhost:8026/test";
        int i = 1;
        while (i < 100) {
            // 每次获取新的连接,测试是否负载均衡
            try (Connection connection = DriverManager.getConnection(url, props)) {
                if ((i % 5) == 0) {
                    PreparedStatement rwStmt = connection.prepareStatement("insert into demo values(?,?)");
                    connection.setReadOnly(false);// 非只读
                    connection.setAutoCommit(false);// 只读
                    rwStmt.setString(1, String.valueOf(i));
                    rwStmt.setString(2, LocalDateTime.now().toString());
                    rwStmt.execute();
                    connection.commit();
                    rwStmt.close();
                } else {
                    connection.setReadOnly(true);// 只读
                }

                Statement roStmt = connection.createStatement();
                ResultSet rs = roStmt.executeQuery("select @@server_id server_id, @@hostname hostname ");
                if (rs.next()) {
                    String output = LocalDateTime.now().toString() + ": server_id=" + rs.getString("server_id")
                            + ", hostname=" + rs.getString("hostname");
                    output += " ( ro=" + connection.isReadOnly() + " )";
                    System.out.println(output);
                }
                rs.close();
                roStmt.close();
                Thread.sleep(1000);

                i++;
            } // end try
        } // end while
    }

注意事项: 复制库对于超级用户root 来说是可写入的,在应用中需要创建一个普通用户,防止从库被写入

需要访问普通用户
CREATE USER 'test'@'%' IDENTIFIED BY  '123456';
--授权 test 数据库给  'test'@'%'
GRANT ALL ON test.* TO 'test'@'%';


在mysql 配置文件中从库需要配置
#对普通用户只读,对超级用户root没用
read_only=ON


如果是注解式事物添加注解  @Transactional(readOnly = true)  

@Bean("myTransactionInterceptor")
    public TransactionInterceptor myTransactionInterceptor() {
      NameMatchTransactionAttributeSource source = new NameMatchTransactionAttributeSource();
      // 只读事务,不做更新操作
      RuleBasedTransactionAttribute readOnlyTx = new RuleBasedTransactionAttribute();
      readOnlyTx.setReadOnly(true);
      //PROPAGATION_SUPPORTS 如果当前有事务则加入,如果没有则不用事务
      //readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
      //支持当前事务,如果当前有事务, 那么加入事务, 如果当前没有事务则新建一个(默认情况)
      readOnlyTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); //需要重新设置事物的传播属性
     
      //支持当前事务,如果当前有事务, 那么加入事务, 如果当前没有事务则新建一个(默认情况)
      RuleBasedTransactionAttribute requiredTx = new RuleBasedTransactionAttribute(
                TransactionDefinition.PROPAGATION_REQUIRED,
                Collections.singletonList(new RollbackRuleAttribute(Exception.class)));
        // requiredTx.setTimeout(5);//设置超时
        Map<String, TransactionAttribute> txMap = new HashMap<>();
        txMap.put("*", readOnlyTx);// 只读事务
        txMap.put("save*", requiredTx);
        txMap.put("insert*", requiredTx);
        txMap.put("update*", requiredTx);
        txMap.put("delete*", requiredTx);
        source.setNameMap(txMap);
        return new TransactionInterceptor(transactionManager, source);
    }


生命周期管理 connectionLifecycleInterceptors

 接口  com.mysql.cj.jdbc.interceptors.ConnectionLifecycleInterceptor
样例 &connectionLifecycleInterceptors=com.app.common.core.MySqlConnectionLifecycleInterceptor

A comma-delimited list of classes that implement "com.mysql.cj.jdbc.interceptors.ConnectionLifecycleInterceptor" that should notified of connection lifecycle events 
(creation, destruction, commit, rollback, setting the current database and changing the autocommit mode) and potentially alter the execution of these commands.
 ConnectionLifecycleInterceptors are "stackable", more than one interceptor may be specified via the configuration property as a comma-delimited list, 
with the interceptors executed in order from left to right

查询拦截 queryInterceptors

queryInterceptors, where you specify the fully qualified names of classes that implement the com.mysql.cj.interceptors.QueryInterceptor interface. In these kinds of interceptor classes, you might change or augment the processing done by certain kinds of statements, such as automatically checking for queried data in a memcached server, rewriting slow queries, logging information about statement execution, or route requests to remote servers

A comma-delimited list of classes that implement "com.mysql.cj.interceptors.QueryInterceptor" that should be placed "in between" query execution to influence the results. QueryInterceptors are "chainable", the results returned by the "current" interceptor will be passed on to the next in in the chain, from left-to-right order, as specified in this property.

连接验证
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html

specify a validation query in your connection pool that starts with /* ping */. Note that the syntax must be exactly as specified. This will cause the driver send a ping to the server and return a dummy lightweight result set. When using a ReplicationConnection or LoadBalancedConnection, the ping will be sent across all active connections.
 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mysql8 window安装,链式复制,双主复制,数据库的负载均衡 的相关文章

  • eclipse行号状态行贡献项是如何实现的?

    我需要更新状态行编辑器特定的信息 我已经有了自己的实现 但我想看看 eclipse 贡献项是如何实现的 它显示状态行中的行号 列位置 谁能指点一下 哪里可以找到源代码 提前致谢 亚历克斯 G 我一直在研究它 它非常复杂 我不确定我是否了解完
  • 如何在 JPQL 或 HQL 中进行限制查询?

    在 Hibernate 3 中 有没有办法在 HQL 中执行相当于以下 MySQL 限制的操作 select from a table order by a table column desc limit 0 20 如果可能的话 我不想使用
  • Android studio - 如何保存先前活动中选择的数据

    这是我的代码片段 这Textview充当按钮并具有Onclicklistner在他们 当cpu1000时Textview单击它会导致cpu g1000其代码如下所示的类 public class Game 1000 extends AppC
  • 将非 Android 项目添加到 Android 项目

    我在 Eclipse 中有三个项目 Base Server 和 AndroidClient Base和Server是Java 1 7项目 而AndroidClient显然是一个android项目 基础项目具有在服务器和 Android 客户
  • Python 的 mysqldb 晦涩文档

    Python 模块 mysqldb 中有许多转义函数 我不理解它们的文档 而且我努力查找它们也没有发现任何结果 gt gt gt print mysql escape doc escape obj dict escape any speci
  • IN 子查询中的 GROUP_CONCAT

    SELECT A id A title FROM table as A WHERE A active 1 AND A id IN SELECT GROUP CONCAT B id from B where user 3 如果我启动子查询SE
  • 如何在.NET中使用java.util.zip.Deflater解压缩放气流?

    之后我有一个转储java util zip Deflater 可以确认它是有效的 因为 Java 的Inflater打开它很好 并且需要在 NET中打开它 byte content ReadSample sampleName var inp
  • 在Java中运行bat文件并等待

    您可能会认为从 Java 启动 bat 文件是一项简单的任务 但事实并非如此 我有一个 bat 文件 它对从文本文件读取的值循环执行一些 sql 命令 它或多或少是这样的 FOR F x in CD listOfThings txt do
  • 对于相同的查询,MySQL Workbench 比 Python 快得多

    MySQL Workbench 中的以下查询需要 0 156 秒才能完成 SELECT date time minute price id FROM minute prices WHERE contract id 673 AND TIMES
  • 不可变的最终变量应该始终是静态的吗? [复制]

    这个问题在这里已经有答案了 在java中 如果一个变量是不可变的并且是final的 那么它应该是一个静态类变量吗 我问这个问题是因为每次类的实例使用它时创建一个新对象似乎很浪费 因为无论如何它总是相同的 Example 每次调用方法时都会创
  • 通过Java从MySQL中获取大量记录

    有一个 MySQL 表 服务器上的用户 它有 28 行和 100 万条记录 也可能会增加 我想从这个表中获取所有行 对它们进行一些操作 然后将它们添加到 MongoDB 中 我知道通过简单的 从用户中选择 操作来检索这些记录将花费大量时间
  • java XMLSerializer 避免复杂的空元素

    我有这个代码 DocumentBuilderFactory factory DocumentBuilderFactory newInstance DocumentBuilder builder factory newDocumentBuil
  • 更新 SQLAlchemy 中的特定行

    我将 SQLAlchemy 与 python 一起使用 我想更新表中等于此查询的特定行 UPDATE User SET name user WHERE id 3 我通过 sql alchemy 编写了这段代码 但它不起作用 session
  • 有没有办法在 MySQL 中有效地对 TRUNCATE 或 DROP TABLE 进行 GRANT ?

    我最近在 MySQL 5 5 x 中尝试过 GRANT SELECT INSERT UPDATE DELETE TRUNCATE ON crawler TO my user localhost WITH GRANT OPTION 这会导致错
  • 子类构造函数(JAVA)中的重写函数[重复]

    这个问题在这里已经有答案了 为什么在派生类构造函数中调用超类构造函数时 id 0 当创建子对象时 什么时候在堆中为该对象分配内存 在基类构造函数运行之后还是之前 class Parent int id 10 Parent meth void
  • Java/Python 中的快速 IPC/Socket 通信

    我的应用程序中需要两个进程 Java 和 Python 进行通信 我注意到套接字通信占用了 93 的运行时间 为什么通讯这么慢 我应该寻找套接字通信的替代方案还是可以使其更快 更新 我发现了一个简单的修复方法 由于某些未知原因 缓冲输出流似
  • Java RMI - 客户端超时

    我正在使用 Java RMI 构建分布式系统 它必须支持服务器丢失 如果我的客户端使用 RMI 连接到服务器 如果该服务器出现故障 例如电缆问题 我的客户端应该会收到异常 以便它可以连接到其他服务器 但是当服务器出现故障时 我的客户端什么也
  • 由 Servlet 容器提供服务的 WebSocket

    上周我研究了 WebSockets 并对如何使用 Java Servlet API 实现服务器端进行了一些思考 我没有花费太多时间 但在使用 Tomcat 进行一些测试时遇到了以下问题 如果不修补容器或至少对 HttpServletResp
  • Spring RESTful控制器方法改进建议

    我是 Spring REST 和 Hibernate 的新手 也就是说 我尝试组合一个企业级控制器方法 我计划将其用作未来开发的模式 您认为可以通过哪些方法来改进 我确信有很多 RequestMapping value user metho
  • java'assert'和'if(){}else exit;'之间的区别

    java和java有什么区别assert and if else exit 我可以用吗if else exit代替assert 也许有点谷歌 您应该记住的主要事情是 if else 语句应该用于程序流程控制 而assert 关键字应该仅用于

随机推荐

  • 修改intelliJ IDEA默认Mvnen插件镜像地址 ,加速依赖安装

    前言 1 3叙述的是如何找到idea的mvnen 如果是手动安装的Mvnen 直接跳到4 本文基于Linux平台 mac windows可作参考 如果是ToolBox安装的IDEA 那么桌面启动程序文件一般在 home USER local
  • 华为OD机试 Python 【五子棋迷】

    题目 张兵和王武喜欢玩五子棋 现在轮到张兵了 他面前的棋盘上有一排棋子 棋子规则 1 表示白子 0 表示没子 是个空位 1 表示黑子 一排棋子中 棋子数量L要满足 1 lt L lt 40 并且L是奇数 你要写个程序帮张兵找到最佳的落子位置
  • 【Apache Spark 】第 3 章Apache Spark 的结构化 API

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • Tomcat提高并发量,性能优化

    系统采用的常用框架 Mysql SSM Tomcat结构 测试工具使用的是Jmeter 刚开始测试 并发量为200 s 居然错误率达到了15 让我很郁闷 按Tomcat的性能200的并发量应该完全没问题 于是我搜了一下提高Tomcat并发量
  • 区块链入门系列之P2P

    区块链入门系列文章 区块链基本概念和名词解释 P2P 共识算法 梅克尔 帕特里夏树 从零开始搭建区块链 这里写自定义目录标题 区块链入门系列文章 前言 中心化架构 去中心化架构 NAT 锥型NAT 完全锥型NAT 非完全锥型NAT IP受限
  • Devops 基础介绍

    文章目录 前言 一 软件开发概述 1 软件开发生命周期 2 软件开发瀑布模型 3 软件的敏捷开发 3 1 迭代开发 3 2 增量开发 3 3 敏捷开发如何迭代 3 4 敏捷开发的好处 二 持续集成概述 1 什么是持续集成 2 持续集成的流程
  • 嵌入式C中__attribute__编译属性说明

    锲而不舍 金石可镂 文章目录 前言 参数介绍 1 aligned 2 packed 3 at 4 section 总结 前言 attribute 是GNU C扩展下一大特性机制 用于设置函数属性 Function Attribute 变量属
  • http及https的 抓包分析

    HTTP及HTTPS实验 1 访问http wwww qq com和https www sangfor com cn并抓包 分析从PC访问到结束访问网站的全数据流过程 2 分析DNS解析过程及请求回应报文结构 掌握DNS报文结构特征和DNS
  • 编译执行和解释执行有什么区别

    什么是脚本 脚本是嵌入式代码 无需编译器就可以在环境中运行 起到解释作用 动态程序一般有两种方式 1 二进制方式是将我们编写的程序进行编译 编程机器可以识别的指令代码 然后再执行 这种已编译好的程序让我们只能执行 使用 却看不他的程序内容
  • vue的常用的属性有哪些?

    new vue el data template methods computed render watch vue总共有7个常用的属性 如上 el 表示一个vue对象需要挂载到哪一个html对象上面 值为那个html对象的id data
  • 【复赛模拟试题】收费站(二分答案+Dijkstra)

    问题描述 在某个遥远的国家里 有n个城市 编号为1 2 3 n 这个国家的政府修建了m条双向的公路 每条公路连接着两个城市 沿着某条公路 开车从一个城市到另一个城市 需要花费一定的汽油 开车每经过一个城市 都会被收取一定的费用 包括起点和终
  • 负载

    参考博客 https baike baidu com item E8 B4 9F E8 BD BD E7 94 B5 E9 98 BB 1136575 fr aladdin http www elecfans com d 938676 ht
  • Python包和库

    2 3 包和库 2 3 1 包的概念 包是在模块之上的概念 为了方便管理而将多个脚本文件 模块文件 进行打包 包是一种用点式模块名构造 Python 模块命名空间的方法 例如 模块名 A B 表示包 A 中名为 B 的子模块 正如模块可以区
  • Vue生成二维码

    文章目录 概要 整体架构流程 实现过程 创建vue VsCode打开项目 打开终端 下载qrcodejs2插件 导入和使用qrcodejs2 代码展示与讲解 概要 实现输入内容后点击回车或生成按钮 生成二维码 扫描后是我们在输入框的值 在上
  • 华为OD机试 - 找到比自己强的人数(Java)

    题目描述 给定数组 2 1 3 2 每组表示师徒关系 第一个元素是第二个元素的老师 数字代表排名 现在找出比自己强的徒弟 输入描述 无 输出描述 无 用例 输入 2 1 3 2 输出 0 1 2 说明 输入 第一行数据 2 1 表示排名第
  • 立刻更新你的苹果设备!苹果被曝2大安全漏洞,无需交互就能被植入间谍软件...

    萧箫 发自 凹非寺量子位 公众号 QbitAI 不要犹豫 立刻更新你的苹果设备 就在这两天 一家安全组织发现了苹果设备的2个最新漏洞 平板 手机 电脑等都受影响 例如搭载iOS 16 6版本的iPhone手机 以及新版本的iPad平板 Ma
  • b宝塔 centos端口更改_宝塔Linux面板添加安全入口,修改管理员默认用户名与端口...

    网站安全问题是件非常容易被忽视掉的事情 有些同学安装宝塔Linux面板之后管理员账号依旧使用的是admin 使用默认的账号密码很容易被入侵 因此猫总总结了使用宝塔面Linux板必须修改的三点 宝塔Windows面板用户同样需要注意安全问题
  • IDEA 下Java获取Tomcat 项目运行路径问题

    最近在学习SpringMVC的上传文件过程中 使session getServletContext getRealPath photo 获取项目运行路径 却发现获取得到的是 C Program Files Apache Software F
  • UBT11:ubuntu安装IDEA2020.1

    11 1 简介 linux上的IDEA并不需要安装 只要解压即可运行 这就好像win上面的绿色软件 所以 我们需要把idea解压到一个合适的位置 然后创建桌面快捷方式 即可完成安装 此方法应该适用于整个JetBrains的软件 11 2 环
  • mysql8 window安装,链式复制,双主复制,数据库的负载均衡

    by xuejianxinokok 163 com 2021年3月25日 周四 15 06 43 1 下载地址 https dev mysql com downloads mysql 2 下载文件名称为 mysql 8 0 23 winx6