mysql脚本

由于工作中需要安装配置相关数据,结合下面相关shell操作数据库,实现删除多余的用户,创建相关数据库并导入数据,实现相关数据库授权,插入相关数据测试
#!/bin/sh
  echo "please  input  Resserveraddress: "
  read  Resserver 
  echo "please  input  Gameserveraddress: "
  read  GameServer
  path=`pwd`
  mysql   -u   root   <<QUERY_SQL  
  DROP     DATABASE    IF         EXISTS     test;
  DROP     DATABASE    IF         EXISTS     testLog;
  DROP    DATABASE    IF   EXISTS     test;
  CREATE   DATABASE   test;
  CREATE   DATABASE   gameLog;
  DELETE   FROM       mysql.user  WHERE      host='localhost.localdomain';
  DELETE   FROM       mysql.user  WHERE      host='127.0.0.1';
  DELETE   FROM       mysql.user  WHERE      user=''; 
  USE   test;
  source $path/test.sql;
  USE   gameLog;
  source $path/testLog.sql; 
  grant all on test.* to "test"@"localhost" identified by "password";
  grant all on testLog.* to "test"@"localhost";
  grant all on test.tbl_sch_account to "test"@"$Resserver" identified by "password";
  grant all on testLog.* to "test"@"$Resserver" identified by "password";
  grant all on testLog.* to "test"@"$GameServer" identified by "password";
  insert into test.tbl_sch_account(email,password) values('test1',md5('111111'));
  insert into test.tbl_sch_account(email,password) values('test2',md5('111111'));
  insert into test.tbl_sch_account(email,password) values('test3',md5('111111'));
  insert into test.tbl_sch_account(email,password) values('test4',md5('111111'));
  insert into test.tbl_sch_account(email,password) values('test5',md5('111111'));
  select * from test.tbl_sch_account;
  show grants;
  show grants for " test"@"$Resserver";
  show grants for " test"@"$GameServer";
  UPDATE mysql.user SET Password=PASSWORD ('password') WHERE User='root';
  QUIT  
  QUERY_SQL

你可能感兴趣的:(mysql,数据库,职场,休闲,mysql脚本)