当前位置: 首页 > wzjs >正文

外贸网站建设网络公司b站推广网站入口2023的推广形式

外贸网站建设网络公司,b站推广网站入口2023的推广形式,网站建设时间查询,网站建设公司上海站霸实现功能 增 数据库的创建,数据表的创建已经实现 创建用户 删 删除数据库, 删除库下的某个表, 删除某个用户 改 暂无 查 查看所有的数据库, 查看某个库下的所有数据表, 查看某个表的结构, 查…

实现功能

数据库的创建,数据表的创建已经实现

创建用户

删除数据库,

删除库下的某个表,

删除某个用户

暂无

查看所有的数据库,

查看某个库下的所有数据表,

查看某个表的结构,

查看某个库的某个表中的所有数据,

查看所有用户

后续计划

准备添加向表中插入数据,包含一次插入多条数据,一次对某列或者多列插入数据

修改某表中的数据

删除表中数据

代码展示

#!/bin/bash
#登录mysql
menu() {
echo -e "\e[32m\t1--查看所有可用数据库\e[0m"
echo -e "\e[32m\t2--查看某个数据库下所有的数据表\e[0m"
echo -e "\e[32m\t3--查看某个库下某个表的结构\e[0m"
echo -e "\e[32m\t4--查看某个库下的某个表中的所有数据\e[0m"
echo -e "\e[32m\t5--创建一个数据库\e[0m"
echo -e "\e[32m\t6--在某个数据库下创建一个数据表\e[0m"
echo -e "\e[32m\t7--在表中插入数据\e[0m"
echo -e "\e[32m\t8--创建一个用户\e[0m"
echo -e "\e[32m\t9--删除数据库\e[0m"
echo -e "\e[32m\t10--删除某个数据库下的数据表\e[0m"
echo -e "\e[32m\t11--删除某个用户信息\e[0m"
echo -e "\e[32m\t12--查看所有用户\e[0m"
echo -e "\e[32m\t13--退出\e[0m"
echo -e "\e[32m\t14--待补充\e[0m"
echo -e "\e[32m\t15--待补充\e[0m"
}
test_db(){
mysql -u${mysql_user:-root} -p"${mysql_password}" -h ${mysql_host:-localhost} -P${mysql_port:-3306} -e "exit" &> /dev/null
if [ $? -eq 0 ];thenecho -e  "\e[32m登录成功,当前数据库信息正确,数据库可以使用\e[0m"echo -e  "\e[35m<-------------------------------------------------------->\e[0m"
elseecho  -e "\e[31m登录失败,数据库用户或密码错误,请重新进行信息收集\e[0m"exit
fi
}
useage() {
echo -e "\e[33m请输入选项1-15\e[0m"
}
date() {
sleep 0.5
}
get_message() {echo -e "\e[33m请先进行数据库登录!!!\e[0m"read -p "请输入你要使用的用户(默认为root):" mysql_usermysql_user=${mysql_user:-root}read -sp "请输入用户密码:"  mysql_passwordecho ""read -p "请输入你要登录的主机(默认为localhost)" mysql_hostmysql_host=${mysql_host:-localhost}read -p "请输入你要登录的服务端口号(默认为3306)" mysql_portmysql_port=${mysql_port:-3306}
}
show_dbs() {
echo -e "\e[32m所有数据库信息如下所示:\e[0m"
date
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "show databases"  2> /dev/null
}
show_tbs() {
read -p "输入你要查看的数据库名(默认为mysql):" db_name
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "use ${db_name:-mysql} ; show tables" 
}
show_tb_desc() {
read -p "输入你要查看的数据库(默认为mysql)" db_name 
read -p "输入你要查看的数据表(默认为user)" tb_name
message=${db_name:-mysql}.${tb_name:-user}
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "desc  $message"
}
select_datas() {
read -p "输入你要查看的数据库(默认为mysql)" db_name 
read -p "输入你要查看的数据表(默认为user)" tb_name
message=${db_name:-mysql}.${tb_name:-user}
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "select * from $message"
read -p "输入g展示旋转后的数据,输入其他跳过" choice
if [ $choice == 'g' ];then 
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "select * from $message\G"    
else 
echo -e "\e[33m跳过\e[0m"
fi
}
create_db() {
read -p "输入你要创建的数据库名(默认为dbs)" db_name
read -p "输入你要创建的数据库默认字符集(默认utf8)" character_name
character_name=${character_name:-utf8}
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "create database if not exists ${db_name:-dbs} default character set $character_name"    
if [ $? -eq 0 ];then echo -e "\e[32m数据库${db_name}创建成功,使用的字符集为"$character_name"\e[0m"dateecho -e  "\e[33m也有可能该数据库已存在,推荐先使用功能9将数据库删除在进行创建\e[0m"
fi
}
create_tb() {
echo "某个库下创建数据表"
read -p "输入你要创建的表名" tb_name
read -p "输入你的创建的表基于的库名" db_name
read -p "输入你的创建的表的默认字符集(默认为utf8)" tb_type
table_message=${db_name:-mysql}.${tb_name:-user}
echo $table_message
read -p "输入你要创建的字段个数" columns_number
for (( i=1; i<=$columns_number; i++ ));doread -p "输入第${i}列的字段名" column_nameread -p "输入第${i}列的数据类型" column_typeread -p "输入第${i}列的约束\n(默认为default null)" column_constraintcolumn_constraint=${column_constraint:-default null}if [ $i -ne $columns_number ] ;thencolumn_message="$column_name $column_type $column_constraint, "column_array[$i]=$column_messageelsecolumn_message="$column_name $column_type $column_constraint"column_array[$i]=$column_messagefidone
echo "所有列的信息为${column_array[@]}"
all_columns="(${column_array[@]})"
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "create table if not exists $table_message $all_columns;" &> /dev/null && echo -e "\e[32m数据表${table_message}创建完成\e[0m" || echo -e "\e[31m数据表${table_message}创建失败\e[0m"
}
insert_data() {
read -p "输入插入表所属库名(默认为mysql)" db_name
read -p "输入你要插入数据的表名(默认为user)" tb_name
tb_message=${db_name:-mysql}.${tb_name:-user}
array=`mysql -u${mysql_user} "-p${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "desc ${tb_message}"  | grep -v "Extra" | awk '{print $1,$2}'`
flag=0
for i in $array;
do flag=$(( $flag + 1 ))if [ $(($flag % 2)) -eq 1 ];thenecho -e  "\e[35m第$(($(($flag + 1 )) / 2 ))个字段名称为$i\e[0m"else echo -e  "\e[35m第$(($flag / 2))个字段类型为$i\e[0m"fi
done
#数据表中的字段已经可以进行收集,剩下数据插入部分后续进行补充
}
show_users() {
echo "当前已经存在的用户"
list=`mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e 'select * from mysql.user\G' | egrep "User|Host" | awk -F":" '{print $NF}'`
number=`mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e 'select * from mysql.user\G'  | egrep "User|Host" | awk -F":" '{print $NF}' | wc -l`
for (( i=1; i<=$number; i++ ));
doflag=$((i%2))if [ $flag -eq 1  ] ;thenhost=`echo $list | cut -d" " -f $i`elseuser=`echo $list | cut -d" " -f $i`message=$user@$hostecho $messagefi
done
}
create_user() {
show_users
read -p "输入你要创建的用户名" user_name
read -p "输入用户可登录的主机(默认为localhost)" host_name 
read -sp "输入你要设置的密码(必须符合密码复杂策略,不输入则为默认密码)" password
echo ""
host_name=\'${host_name:-localhost}\'
user_message=$user_name@$host_name
password=\'${password:-'ABCDE2002@'}\'
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "create user ${user_message} identified by ${password};" &> /dev/null && echo -e "\e[32m用户${user_message}创建成功\e[0m"  || echo -e  "\e[31m用户${user_message}创建失败\e[0m"   
}
drop_db() {
read -p "输入你要删除的数据库" db_name 
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "drop database if exists $db_name;" &> /dev/null
if [ $? -eq 0 ];thenecho -e "\e[32m数据库${db_name}成功删除\e[0m"dateecho -e "\e[33m数据库${db_name}也可能本身就不存在\e[0m" 
fi
}
drop_tb() {
read -p "输入你要删除的数据表所在的数据库" db_name
read -p "输入你要删除的数据表" tb_name
drop_message=$db_name.$tb_name
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "drop table if exists $drop_message;" &> /dev/null
if [ $? -eq 0 ];thenecho -e "\e[32m数据表${drop_message}成功删除\e[0m"dateecho -e "\e[33m数据表${drop_message}也可能本身就不存在\e[0m" 
fi
}
drop_user() {
show_users
read -p "输入你要删除的用户名" user_name
read -p "输入你要删除的用户主机(默认为localhost)" host_name
host_name=\'${host_name:-localhost}\'
user_message=$user_name@$host_name
echo $message
mysql -u${mysql_user} -p"${mysql_password}" -h ${mysql_host} -P${mysql_port} -e "drop user if exists $user_message;" &> /dev/null && echo -e "\e[32m用户${user_message}删除成功\e[0m"
}
main() {
get_message
test_db
while true;domenuread -p "输入你要使用的功能" choicecase $choice in 1) show_dbsdate;;2) show_tbsdate;;3) show_tb_descdate;;4) select_datasdate;;5) create_dbdate;;6) create_tbdate;;7) insert_datadate;;8) create_userdate;;9) drop_dbdate;;10) drop_tbdate;;11) drop_userdate;;12) show_usersdate;;13) break;;14) echo "待补充";;15) echo "待补充"date;;*)useagedate;;esac 
done
}
main

http://www.dtcms.com/wzjs/328478.html

相关文章:

  • 贵金属如何用网站开发客户公司网站域名续费一年多少钱
  • 地下城做解封任务的网站赣州网站建设
  • 毕业设计做旅游网站搜索引擎分析论文
  • 做软件工资高还是网站百度热门排行榜
  • 如何用电脑做网站服务器腾讯朋友圈广告怎么投放
  • 怎么做国外网站前端seo怎么优化
  • 地方文明网站建设中国十大营销策划机构
  • 如何做网站内链seo目标关键词优化
  • 给网站底部做友情链接手机百度最新正版下载
  • 网站用的服务器是什么优化英语
  • 四川建设网站官网推广产品最好的方式
  • 福州网络营销推广公司宁波seo快速优化平台
  • 现在什么网站比较火做推广上海网站制作公司
  • linux网站开发工具怎么建网站赚钱
  • 多用户网站建设方案短视频怎么赚钱
  • 绵阳网站建设2023新闻摘抄大全
  • 小程序源码网站论坛原创软文
  • 做外贸网站的价格网站seo的主要优化内容
  • 网站建设公司怎么做业务排名怎么优化快
  • 怎么制作图片加文字带声音的视频武汉seo优化
  • 做企业网站域名需要解析吗上海app网络推广公司
  • 网站蜘蛛爬行统计系统百度关键词排名靠前
  • php动态网站开发实训教程百度关键词首页排名怎么上
  • 网站即将 模板初学者做电商怎么入手
  • wordpress用外部图片长沙seo霜天
  • 宁波公司地址做seo必须有网站吗
  • 阿里云中文域名建设网站网络推广外包哪个公司做的比较好
  • java ee只是做网站吗网站提交收录入口
  • 三网合一网站 东莞郴州网站建设推广公司
  • 株洲网站开发长春网站建设方案优化