zoukankan      html  css  js  c++  java
  • CockroachDB 备忘

    wget -qO- https://binaries.cockroachdb.com/cockroach-v19.2.2.linux-amd64.tgz | tar xvz

    cp -i cockroach-v19.2.2.linux-amd64/cockroach /usr/local/bin/

    --启动第一个节点
    cockroach start --insecure --store=n1 --host=10.10.14.188 --http-port=8081 --background


    启动第二个节点
    cockroach start --insecure --store=n2 --host=10.10.14.187 --http-port=8081 --join=10.10.14.188:26257 --background


    cockroach start --insecure --store=n3 --host=10.10.14.189 --http-port=8081 --join=10.10.14.188:26257 --background

    --非安全模式链接数据库
    cockroach sql --host=10.10.14.188 --insecure


    --创建数据库:
    create database testDb;

    --创建 表
    CREATE TABLE IF NOT EXISTS person (number INT PRIMARY KEY, name STRING,birthday DATE)

    --创建用户
    cockroach user set dsideal --host=10.10.14.188 --insecure

    --为用户授权可以使用哪个库
    cockroach sql --host=10.10.14.188 --insecure -e 'GRANT ALL ON DATABASE testdb TO dsideal'


    --创建索引
    CREATE INDEX ON student (type_id);


    --JAVA代码 

    JAR包地址:链接: https://pan.baidu.com/s/1uiNTxetRYOj7TwJ394NkLQ 提取码: n2x7 

    package com.dsideal;

    import java.sql.*;
    import java.util.Properties;

    public class test01 {

    public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stubClass.forName("org.postgresql.Driver");

    // Connect to the "bank" database.
    Properties props = new Properties();
    props.setProperty("user", "dsideal");
    //非安全模式
    props.setProperty("sslmode", "disable");
    //安全模式
    //props.setProperty("sslmode", "require");
    //props.setProperty("sslrootcert", "certs/ca.crt");
    //props.setProperty("sslkey", "certs/client.maxroach.pk8");
    //props.setProperty("sslcert", "certs/client.maxroach.crt");

    Connection db = DriverManager
    .getConnection("jdbc:postgresql://10.10.14.188:26257/testdb", props);

    try {
    // Create the "accounts" table.
    db.createStatement()
    .execute("CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT)");

    // Insert two rows into the "accounts" table.
    db.createStatement()
    .execute("INSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250)");

    // Print out the balances.
    System.out.println("Initial balances:");
    ResultSet res = db.createStatement()
    .executeQuery("SELECT id, balance FROM accounts");
    while (res.next()) {
    System.out.printf(" account %s: %s ",
    res.getInt("id"),
    res.getInt("balance"));
    }
    } finally {
    // Close the database connection.
    db.close();
    }

    }

    }

  • 相关阅读:
    POJ1995 ZOJ2150 Raising Modulo Numbers【快速模幂】
    POJ3641 UVA11287 HDU1905 Pseudoprime numbers【素数判定+快速模幂】
    ACM题解系列之三:秋田拓哉:《挑战程序设计竞赛》(第2版)
    HDU3257 Hello World!【打印图案+位运算】
    ACM题解系列之二:刘汝佳:《算法竞赛入门经典训练指南》
    UVa10881 Piotr's Ants【模拟】
    POJ1852 UVa10714 Ants【水题】
    剑指Offer——平衡二叉树
    剑指Offer——二叉树的深度
    剑指Offer——数字在排序数组中出现的次数
  • 原文地址:https://www.cnblogs.com/kgdxpr/p/12161241.html
Copyright © 2011-2022 走看看