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

湖北省建设厅行政审批网站微信公众号端网站开发

湖北省建设厅行政审批网站,微信公众号端网站开发,wordpress付款插件,小蝌蚪视频网络科技有限公司实现功能 增 数据库的创建,数据表的创建已经实现 创建用户 删 删除数据库, 删除库下的某个表, 删除某个用户 改 暂无 查 查看所有的数据库, 查看某个库下的所有数据表, 查看某个表的结构, 查…

实现功能

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

创建用户

删除数据库,

删除库下的某个表,

删除某个用户

暂无

查看所有的数据库,

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

查看某个表的结构,

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

查看所有用户

后续计划

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

修改某表中的数据

删除表中数据

代码展示

#!/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/617300.html

相关文章:

  • 黔西南州建设局网站校园网站建设与管理
  • 面试建设单位在哪个网站推广什么意思
  • 杂志社网站建设方案安康微平台
  • 河南做网站推广哪个好百度网盘搜索引擎盘多多
  • 怎样建立自己的销售网站wdcp wordpress
  • 成都网站建设cdajcxwordpress侧边栏显头像
  • 网站个人信息页面布局wordpress恢复旧编辑器
  • 玉林网站推广国外网站查询
  • 小程序如何开发制作seo优化轻松seo优化排名
  • 长春cms建站wordpress模板克隆
  • 闵行北京网站建设wordpress打赏后插件
  • 帝国cms 网站地图标签wordpress 导出功能
  • 个性化定制网站的特点手游网站源码下载
  • 珠海 网站开发win2003服务器网站管理工具
  • wap站是什么意思啊旅游公司网站开发
  • 如何创造免费网站适合新手的网站开发
  • 静态网站入侵兰州网站的建设
  • wordpress所有外链本地化适合seo优化的网站
  • htm商城网站开发wordpress 获取当前分类名称
  • 网站网站是否需要备案wordpress 定期删除
  • 服务哪家好网站制作论文引用网站数据 如何做注释
  • 衡水市网站建设保定关键词排名推广
  • 微信公众号网站开发模板wordpress插件dflip
  • 北京做网站建设比较好的公司wordpress 视频大小
  • 网站建设实验步骤建设部网站已经公布黑名单
  • 网站内做动图网站建设每年有维护费吗
  • 淄博外贸网站建设wordpress模板应用
  • 网站开发详情中装建设集团有限公司
  • 影楼网站推广手机网站这么做链接
  • 大型商城网站建设方案wordpress网址改坏了