TiDB入门篇-SQL基本操作和修改TiDB系统参数

简介

简单的操作下tidb。

SQL的基本操作

#连接tidb
mysql --comments --host 192.168.66.10 --port 4000 -u root -p

#查看版本
select tidb_version()\G

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.5.1
Edition: Community
Git Commit Hash: 4084b077d615f9dc0a41cf2e30bc6e1a02332df2
Git Branch: heads/refs/tags/v6.5.1
UTC Build Time: 2023-03-07 16:12:08
GoVersion: go1.19.5
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

show databases;
create database tidb;
use tidb;

#查询当前数据库的连接状态
show processlist;
mysql> show processlist;
+---------------------+------+---------------------+------+---------+------+------------+------------------+
| Id                  | User | Host                | db   | Command | Time | State      | Info             |
+---------------------+------+---------------------+------+---------+------+------------+------------------+
| 5422540659540099479 | root | 192.168.66.10:41146 | NULL | Query   |    0 | autocommit | show processlist |
+---------------------+------+---------------------+------+---------+------+------------+------------------+

修改TiDB系统参数

实验准备

use test;
create table t1 (a int not null primary key auto_increment);
show session variables like 'auto_increment_increment';

mysql> use test;
Database changed
mysql> create table t1 (a int not null primary key auto_increment);
Query OK, 0 rows affected (0.12 sec)

#现在默认的自增加是1
mysql> show session variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
+--------------------------+-------+
1 row in set (0.00 sec)

insert into t1 values();
insert into t1 values();
select * from t1;
mysql> select * from t1;
+---+
| a |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.00 sec)

会话级别修改参数

#会话级别修改参数 
#修改auto_increment_increment为10
set auto_increment_increment = 10;
insert into t1 values();
insert into t1 values();
select * from t1;
mysql> insert into t1 values();
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+----+
| a  |
+----+
|  1 |
|  2 |
| 11 |
| 21 |
+----+
4 rows in set (0.00 sec)
mysql> show variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 10    |
+--------------------------+-------+
1 row in set (0.00 sec)
#重新启动一个会话
mysql --comments --host 192.168.66.10 --port 4000 -u root -p
use test;
insert into t1 values();
insert into t1 values();
select * from t1;

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into t1 values();
Query OK, 1 row affected (0.01 sec)

mysql> insert into t1 values();
Query OK, 1 row affected (0.01 sec)

mysql> select * from t1;
+----+
| a  |
+----+
|  1 |
|  2 |
| 11 |
| 21 |
| 22 |
| 23 |
+----+
6 rows in set (0.00 sec)
mysql> show variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
+--------------------------+-------+
1 row in set (0.00 sec)

在GLOBAL范围进行修改

mysql --comments --host 192.168.66.10 --port 4000 -u root -p
#在GLOBAL范围进行修改
use test;
set global auto_increment_increment = 10;
show variables like 'auto_increment_increment';
#可以看到使用global修改的参数在现在的会话没有生效
mysql> show variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
+--------------------------+-------+
1 row in set (0.00 sec)
exit;
#对出重新连接看下,可以看到在下一次会话的时候生效了
mysql --comments --host 192.168.66.10 --port 4000 -u root -p
mysql> show variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 10    |
+--------------------------+-------+
1 row in set (0.00 sec)

重启集群以后可以看到全局设置的确存储到了tikv上面了 

#重启集群
tiup cluster stop tidb-deploy
tiup cluster start tidb-deploy
mysql --comments --host 192.168.66.10 --port 4000 -u root -p
use test;
mysql> show variables like 'auto_increment_increment';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 10    |
+--------------------------+-------+
1 row in set (0.00 sec)

修改集群配置

#修改集群配置
上面修改的系统配置现在修改集群配置
修改配置参数名为log-level,其值为info,我们将其修改为warning

cd /tidb-deploy/tikv-20160/conf
[root@master conf]# cat tikv.toml 
# WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
# You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
# All configuration items you want to change can be added to:
# server_configs:
#   tikv:
#     aa.b1.c3: value
#     aa.b2.c4: value

#进入到tiup的中控机执行下面的配置命令
tiup cluster edit-config tidb-deploy
#修改下面的配置,这个修改以后所有的tikv.toml配置都会修改
global:
  user: tidb
  ssh_port: 22
  ssh_type: builtin
  deploy_dir: /tidb-deploy
  data_dir: /tidb-data
  os: linux
  arch: amd64
server_configs:
  tidb: {}
  tikv:
    log-level: warning

#重新加载配置(reload的时候集群轮训的一个重启状态,不会影响正常的服务)
tiup cluster reload tidb-deploy

#查看修改的效果
cd /tidb-deploy/tikv-20160/conf
cat tikv.toml
[root@master conf]# cat tikv.toml
# WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
# You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
# All configuration items you want to change can be added to:
# server_configs:
#   tikv:
#     aa.b1.c3: value
#     aa.b2.c4: value
log-level = "warning"

猜你喜欢

转载自blog.csdn.net/S1124654/article/details/129768408
今日推荐