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

域名格式是什么广州:推动优化防控措施落地

域名格式是什么,广州:推动优化防控措施落地,龙岩网站建设要多久,在github做网站实现功能 增 数据库的创建,数据表的创建已经实现 创建用户 删 删除数据库, 删除库下的某个表, 删除某个用户 改 暂无 查 查看所有的数据库, 查看某个库下的所有数据表, 查看某个表的结构, 查…

实现功能

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

创建用户

删除数据库,

删除库下的某个表,

删除某个用户

暂无

查看所有的数据库,

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

查看某个表的结构,

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

查看所有用户

后续计划

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

修改某表中的数据

删除表中数据

代码展示

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

相关文章:

  • 加拿大计划网站怎么做怎么推广自己的微信号
  • 支付网站怎么做的seo教程培训
  • 苏州高端网站制作官网莆田百度推广开户
  • 招聘网站做一下要多少钱东莞做网站哪家好
  • 结合七牛云 做视频网站百度统计数据
  • 网站建设成本明细整站优化全网营销
  • wordpress ftp 插件需要优化的网站有哪些?
  • 江阴哪家做网站便宜设计外包网站
  • 做本地网站百度推广按点击收费
  • 网站服务器空间选择易观数据app排行
  • 公司网站如何推广免费的网站
  • 杭州临平网站建设创建网页
  • 北京市建设委员会网站资质办理海豹直播nba
  • 信阳住房和城乡建设厅网站网络销售怎么才能找到客户
  • iis 网站 红百度seo快排软件
  • vi设计网站排行榜西安区seo搜索排名优化
  • 网站开发命名规则百度一下就知道官方
  • asp.net网站建设论文网络推广公司是干什么
  • 做网站可以自由职业吗清远新闻最新
  • 海南海口做网站关键词是什么
  • 网站建设中正在为您转关键词排名软件
  • 找手工活带回家做的找工作哪个网站最靠谱网络营销公司网络推广
  • 推荐几个做网站比较好的公司小红书推广方式
  • 坪山附近网站建设大数据
  • 网站访客qq提取拼多多怎么查商品排名
  • 一级a做爰片免费无码网站友情链接买卖代理
  • 网站建设与用户体验关键词优化推广公司
  • 做网站 花时间购买友情链接
  • 携程旅行网站内容的建设网络营销公司哪家可靠
  • 个体工商营业执照注册查询金华seo全网营销