mysql脚本

本文介绍了一种使用Shell脚本来配置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

本文转自 qwjhq 51CTO博客,原文链接:http://blog.51cto.com/bingdian/170711
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值