gbase8s之mysql的show命令实现

第一步:生成show.sh脚本

cat /home/gbase/show.sh

#!/bin/bash

#作者:乡村野中医

#创作时间2024-11-21

#脚本名称show.sh

function show(){

#echo $#

if [ "xdatabases" = x$1 ]

then

echo "select name from sysdatabases;"|dbaccess sysmaster - 2>/dev/null|grep name|sed 's/name/\n/g'

elif [ "xtables" = x$1 ]

then

if [ "x" = "x${database_name}" ]

then

echo '请执行use 库名'

else

#echo "database_name:${database_name}"

echo "select tabname from systables where tabid>99;"|dbaccess $database_name - 2>/dev/null|grep tabname|sed 's/tabname/\n/g'

fi

else

echo '执行命令报错,想查看库请执行show databases'

fi

}

function use(){

if [ x != x$1 ]

then

read -p "gbase>" s t

if [ "xshow tables" != xst ]

then

database_name=$1

#echo "database_name:$database_name"

show tables

fi

else

echo "语法报错,想查看某个库的表请执行 use 库名,show tables"

fi

}

第二步:写入gbasedbt用户的.bash_profile里

su - gbasedbt

echo "source show.sh" >> .bash_profile

第三步:测试命令

1,查看所有库

show databases

2,查看某库的所有业务表

use testdb

>show tables

相关推荐
SmartBrain1 天前
FastAPI实战(第三部分):浏览历史的接口开发详解
数据库·人工智能·aigc·fastapi
山岚的运维笔记1 天前
SQL Server笔记 -- 第77章:文件组
数据库·笔记·sql·microsoft·oracle·sqlserver
有点心急10211 天前
Python 入门
服务器·数据库·python
独泪了无痕1 天前
Mac Homebrew 安装 MySQL 指南
数据库·mysql·mac
l1t1 天前
DeepSeek总结的PostgreSQL 19新功能:第二部分
数据库·postgresql
fchampion1 天前
MYSQL自学笔记
数据库·笔记·mysql
XiaoHu02071 天前
MySQL基础(第一弹)
数据库·c++·mysql
惜分飞1 天前
rose双机引起文件系统损坏使得数据库异常故障处理---惜分飞
数据库·oracle
小小工匠1 天前
大模型开发 - SpringAI之MySQL存储ChatMemory
mysql·spring ai
fchampion1 天前
MYSQL分析案例
数据库·mysql