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();
    }

    }

    }

  • 相关阅读:
    洛谷1894 [USACO4.2]完美的牛栏The Perfect Stall
    洛谷2417 课程
    洛谷2860 [USACO06JAN]冗余路径Redundant Paths
    洛谷1983 车站分级
    BZOJ1178或洛谷3626 [APIO2009]会议中心
    BZOJ1179或洛谷3672 [APIO2009]抢掠计划
    CF Round #516 (Div. 2, by Moscow Team Olympiad)
    洛谷1262 间谍网络
    NOI导刊 2018河南郑州游记
    BZOJ1001或洛谷4001 [BJOI2006]狼抓兔子
  • 原文地址:https://www.cnblogs.com/kgdxpr/p/12161241.html
Copyright © 2011-2022 走看看