zoukankan      html  css  js  c++  java
  • shell脚本操作mysql数据库—创建数据库,在该数据库中创建表(插入,查询,更新,删除操作也可以做)

    #!/bin/bash

    HOSTNAME="192.168.1.224"                                           #数据库Server信息
    PORT="3306"
    USERNAME="root"
    PASSWORD="123456"

    DBNAME="test_db_name"                                              #要创建的数据库的库名称
    TABLENAME="test_table_name"                                  #要创建的数据库的表的名称

    MYSQL_CMD="mysql -h${HOSTNAME}  -P${PORT}  -u${USERNAME} -p${PASSWORD}"
    echo ${MYSQL_CMD}

    echo "create database ${DBNAME}"

    create_db_sql="create database IF NOT EXISTS ${DBNAME}"
    echo ${create_db_sql}  | ${MYSQL_CMD}                         #创建数据库                   
    if [ $? -ne 0 ]                                                                                #判断是否创建成功
    then
     echo "create databases ${DBNAME} failed ..."
     exit 1
    fi


    echo "create table ${TABLENAME}"

    create_table_sql="create table ${TABLENAME}(
    name char(6) NOT NULL,
    id int default 0
    )ENGINE=MyISAM DEFAULT CHARSET=latin1"
    echo ${create_table_sql} | ${MYSQL_CMD} ${DBNAME}              #在给定的DB上,创建表
    if [ $? -ne 0 ]                                                                                                #判断是否创建成功
    then
     echo "create  table ${DBNAME}.${TABLENAME}  fail ..."
    fi

    from:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201141142057473/

    hadoop大数据相关
  • 相关阅读:
    缓存架构设计细节二三事
    啥,又要为表增加一列属性?
    SpringMvc4.x---快捷的ViewController
    SpringMvc4.x--@ControllerAdvice注解
    SpringMvc4.x--Spring MVC的常用注解
    解决svn--Unable to connect to a repository at URL ‘https://xxxxxx’ 问题
    或许你不知道的10条SQL技巧
    Java 基础-运算符
    Java 运算符 % 和 /
    Java基础-注释
  • 原文地址:https://www.cnblogs.com/zhangzl/p/4566155.html
Copyright © 2011-2022 走看看