ych

          2007年5月23日

          通過exp導(dǎo)出與imp導(dǎo)入進(jìn)行數(shù)據(jù)的備份轉(zhuǎn)移:
          exp命令:
          1 exp username/psw@TEST file=d:test.dmp full=y
          2 exp username/psw@TEST file=d:test.dmp owner=(ly)
          3 exp username/psw@TEST file= d:test.dmp tables=(grid1,grid2)
          1其中一是將Test(與某一數(shù)據(jù)庫(kù)對(duì)應(yīng)的oracle服務(wù)名)數(shù)據(jù)庫(kù)進(jìn)行整體導(dǎo)出
          2將屬于用戶ly的所有表導(dǎo)出
          3將表grid1,與grid2導(dǎo)出
          d:test.dmp是導(dǎo)出的文件地址

          imp命令:
          1 imp system/psw@TEST  file=d:test.dmp
          2 imp system/psw@TEST  full=y  file=d:test.dmp ignore=y
          3 imp system/psw@TEST  file=d:test.dmp  tables=(grid1)
          ignore=y表示如果被導(dǎo)入的數(shù)據(jù)庫(kù)中某個(gè)表已經(jīng)存在就忽略不導(dǎo)入那個(gè)表
          3表示只導(dǎo)入grid1這個(gè)表

          在導(dǎo)入導(dǎo)出前要先測(cè)試下對(duì)應(yīng)的數(shù)據(jù)庫(kù)是否是通的:tnsping test來測(cè)試,同樣test是服務(wù)名
          所有命令可在cmd下執(zhí)行
          posted @ 2008-09-03 11:57 changhong 閱讀(97) | 評(píng)論 (0)編輯 收藏

          http://blog.csdn.net/techyang/archive/2005/08/09/448677.aspx(luanfengxia/arc/2006/05/20/746951.aspx)

           public ActionForward add(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response) throws Exception {
                  String encoding = request.getCharacterEncoding();
                  if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))
                  {
                      response.setContentType("text/html; charset=gb2312");//如果沒有指定編碼,編碼格式為gb2312
                  }
                  NodeForm theForm = (NodeForm) form;
                  String nodename=theForm.getNodename();
                  String note=theForm.getNote();
                  FormFile file = theForm.getTheFile1();//取得上傳的文件
                  FormFile file2=theForm.getTheFile2();
                  FormFile file3=theForm.getTheFile3();
                  Session session=null;
                  String forward="";
                  try
                  {
                      /*
                       * 取當(dāng)前系統(tǒng)路徑
                       */
                      String filePath = this.getServlet().getServletContext()
                      .getRealPath("/");
                      System.out.println("---------------------------------------"+filePath);
                      if(file.getFileSize()!=0){
                      ByteArrayInputStream stream = (ByteArrayInputStream) file.getInputStream();//把文件讀入
                    
                      //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    
                      /*
                       * 建立一個(gè)上傳文件的輸出流
                       */
                      OutputStream bos = new FileOutputStream(filePath +
                              "UploadFiles\\"+file.getFileName());
                      request.setAttribute("fileName",filePath + "/"
                              + file.getFileName());
                      int bytesRead = 0;
                      byte[] buffer = new byte[8192];
                      while ((bytesRead = stream.read(buffer, 0, 8192)) != -1)
                      {
                          bos.write(buffer, 0, bytesRead);//將文件寫入服務(wù)器
                      }          
                      bos.close();
                      stream.close();
                      }if(file2.getFileSize()!=0){
                      ByteArrayInputStream stream2 = (ByteArrayInputStream) file2.getInputStream();
                      OutputStream bos2 =  new FileOutputStream(filePath +
                              "UploadFiles\\"+file2.getFileName());//建立一個(gè)上傳文件的輸出流
                      int bytesRead2 = 0;
                      byte[] buffer2 = new byte[8192];
                      while ((bytesRead2 = stream2.read(buffer2, 0, 8192)) != -1)
                      {
                          bos2.write(buffer2, 0, bytesRead2);//將文件寫入服務(wù)器
                      }          
                      bos2.close();
                      stream2.close();
                      }if(file3.getFileSize()!=0){
                      ByteArrayInputStream stream3 = (ByteArrayInputStream) file3.getInputStream();//把文件讀入
                  OutputStream bos3 =  new FileOutputStream(filePath +
                          "UploadFiles\\"+file3.getFileName());//建立一個(gè)上傳文件的輸出流
                  int bytesRead3 = 0;
                  byte[] buffer3 = new byte[8192];

                  while ((bytesRead3 = stream3.read(buffer3, 0, 8192)) != -1)
                  {
                      bos3.write(buffer3, 0, bytesRead3);//將文件寫入服務(wù)器
                  }          
                  bos3.close();
                  stream3.close();
                  }
            Configuration config = new Configuration().configure();
            SessionFactory factory = config.buildSessionFactory();
               session = factory.openSession();
                  Transaction transaction = session.beginTransaction();
                  Node node=new Node();
                  node.setNodeName(nodename);
                  node.setXsdName(file.getFileName());
                  node.setXslName(file2.getFileName());
                  node.setXhtmlName(file3.getFileName());
                  node.setNote(note);
                  session.save(node);
            session.flush();
            session.clear();
            forward="display";
                  transaction.commit();
                  }
                  catch (Exception e)
                  {
                   forward="error";
                      System.err.print(e);
                      e.printStackTrace();
                  }
             
            finally{
             session.close();
             }
                  return mapping.findForward(forward);
           }

          posted @ 2007-08-29 13:35 changhong 閱讀(208) | 評(píng)論 (0)編輯 收藏
          "^\\d+$"  //非負(fù)整數(shù)(正整數(shù) + 0)
          "^[0-9]*[1-9][0-9]*$"  //正整數(shù)
          "^((-\\d+)|(0+))$"  //非正整數(shù)(負(fù)整數(shù) + 0)
          "^-[0-9]*[1-9][0-9]*$"  //負(fù)整數(shù)
          "^-?\\d+$"    //整數(shù)
          "^\\d+(\\.\\d+)?$"  //非負(fù)浮點(diǎn)數(shù)(正浮點(diǎn)數(shù) + 0)
          "^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"  //正浮點(diǎn)數(shù)
          "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"  //非正浮點(diǎn)數(shù)(負(fù)浮點(diǎn)數(shù) + 0)
          "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"  //負(fù)浮點(diǎn)數(shù)
          "^(-?\\d+)(\\.\\d+)?$"  //浮點(diǎn)數(shù)
          "^[A-Za-z]+$"  //由26個(gè)英文字母組成的字符串
          "^[A-Z]+$"  //由26個(gè)英文字母的大寫組成的字符串
          "^[a-z]+$"  //由26個(gè)英文字母的小寫組成的字符串
          "^[A-Za-z0-9]+$"  //由數(shù)字和26個(gè)英文字母組成的字符串
          "^\\w+$"  //由數(shù)字、26個(gè)英文字母或者下劃線組成的字符串
          "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$"    //email地址
          "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$"  //url
          posted @ 2007-07-06 19:14 changhong 閱讀(136) | 評(píng)論 (0)編輯 收藏

          1連接數(shù)據(jù)庫(kù):

          進(jìn)入mysql的安裝路徑bin如:C:>cd C:Program FilesMySQLMySQL Server 5.0bin

          輸入用戶名密碼: C:Program FilesMySQLMySQL Server 5.0bin>mysql -uroot -p123456

          2退出mysql

          mysql>exit

          3. 修改密碼:
          C:Program FilesMySQLMySQL Server 5.0bin>mysqladmin -uroot -p123456 password 456123

          4.增加用戶:
          添加一個(gè)用戶test1 密碼為ABC;讓他可以在任何主機(jī)上登錄,并對(duì)所有數(shù)據(jù)庫(kù)有查詢、插入、修改、刪除的權(quán)限。首先用以root用戶連入mysql,

          mysql>grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";

          增加一個(gè)用戶test2密碼為abc,讓其只可以在localhost上登錄,并可以對(duì)數(shù)據(jù)庫(kù)mydb進(jìn)行查詢、插入、修改、刪除的操作(localhost指本地主機(jī),即mysql數(shù)據(jù)庫(kù)所在的那臺(tái)主機(jī)),這樣用戶即使用知道test2的密碼,也無法從internet上直接訪問數(shù)據(jù)庫(kù),只能通過mysql主機(jī)上的web頁來訪問了。

          mysql>grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";

          增加一個(gè)可以從任何地方連接服務(wù)器的一個(gè)完全的超級(jí)用戶
          mysql>grant all privileges on *.* to test3@"%" identified by 'abc' with grant option;

          5.刪除授權(quán)(與上面授權(quán)相對(duì)應(yīng))

          mysql>revoke select,insert,update,delete on *.* from test1@"%" ;

          mysql>revoke select,insert,update,delete on mydb.* from test2@localhost;

          mysql>revoke all privileges on *.* from test3@"%";

          6.顯示數(shù)據(jù)庫(kù)
          mysql>show databases;

          7.顯示數(shù)據(jù)庫(kù)中的表(exam數(shù)據(jù)庫(kù)名)
          mysql>use exam;
          mysql>show tables;

          8.顯示表的結(jié)構(gòu)(db_testtemp表名)
          mysql>describe db_testtemp;

          9.建庫(kù)
          mysql>create database 庫(kù)名;

          10.建表
          mysql>use test;
          mysql>create table teacher(

          id int(3) auto_increment not null primary key,

          name char(10) not null,

          address varchar(50) default 'beijing',

          year date

          );

          或者

          school.sql的內(nèi)容

          use exam;
          create table teacher(

          id int(3) auto_increment not null primary key,

          name char(10) not null,

          address varchar(50) default 'beijing',

          year date

          );

          把文件school.sql放到c:下,并在DOS狀態(tài)進(jìn)入目錄C:>cd C:Program FilesMySQLMySQL Server 5.0bin
          然后C:Program FilesMySQLMySQL Server 5.0bin>mysql -uroot -p456123 < c:school.sql
          如果成功,空出一行無任何顯示;如有錯(cuò)誤,會(huì)有提示。

          11.刪除庫(kù)
          mysql>drop database test;

          和刪除表

          mysql>use exam;
          mysql>drop table teacher;

          14.表重命名
          mysql>alter table teacher rename student;

          15. 備份數(shù)據(jù)庫(kù)(生成的exam.sql放在目錄C:Program FilesMySQLMySQL Server 5.0bin下)
          C:Program FilesMySQLMySQL Server 5.0bin>mysqldump -hlocalhost -uroot -pncae2010 exam > exam.sql

          16. 恢復(fù)數(shù)據(jù)庫(kù)(localhost不能用本機(jī)IP代替)
          C:Program FilesMySQLMySQL Server 5.0bin>mysql -hlocalhost -uroot -pncae2010 exam < exam.sql

          17.復(fù)制數(shù)據(jù)庫(kù)(把所有的數(shù)據(jù)庫(kù)備份到目錄C:Program FilesMySQLMySQL Server 5.0bin下的all-databases.sql文件中)
          C:Program FilesMySQLMySQL Server 5.0bin>mysqldump -hlocalhost -uroot -pncae2010 --all-databases > all-databases.sql

          18.備份表(生成的student.sql放在目錄C:Program FilesMySQLMySQL Server 5.0bin下)


          C:Program FilesMySQLMySQL Server 5.0bin>mysqldump -hlocalhost -uroot -pncae2010 exam student > student.sql

           

          19.恢復(fù)表(操作前先把原來的表刪除)
          C:Program FilesMySQLMySQL Server 5.0bin>mysql -h(ip) -uroot -p(password) databasename tablename < tablename.sql

          還有一些未實(shí)踐

          20.為了改變列a,從INTEGER改為TINYINT NOT NULL(名字一樣),
          并且改變列b,從CHAR(10)改為CHAR(20),同時(shí)重命名它,從b改為c:
          ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE b c CHAR(20);

          增加一個(gè)新TIMESTAMP列,名為d:
          ALTER TABLE t2 ADD d TIMESTAMP;

          在列d上增加一個(gè)索引,并且使列a為主鍵:
          ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a);

          刪除列c:
          ALTER TABLE t2 DROP COLUMN c;

          增加一個(gè)新的AUTO_INCREMENT整數(shù)列,命名為c:
          ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT,ADD INDEX (c);
          注意,我們索引了c,因?yàn)锳UTO_INCREMENT柱必須被索引,并且另外我們聲明c為NOT NULL,
          因?yàn)樗饕说牧胁荒苁荖ULL

          ---------------------------------------------------------------

          21.數(shù)據(jù)的導(dǎo)入導(dǎo)出
          A。mysqlimport
          語法:mysqlbinmysqlimport database tables.txt( 文件名需要與表名相同)
          參數(shù):-d or --delete 新數(shù)據(jù)導(dǎo)入數(shù)據(jù)表中之前刪除數(shù)據(jù)數(shù)據(jù)表中的所有信息;
          -f or --force 不管是否遇到錯(cuò)誤
          -i or --ignore mysqlimport跳過或者忽略那些有相同唯一關(guān)鍵字的行, 導(dǎo)入文件中的數(shù)據(jù)將被忽略;
          -l or -lock-tables 數(shù)據(jù)被插入之前鎖住表,這樣就防止了, 你在更新數(shù)據(jù)庫(kù)時(shí),用戶的查詢和更新受到影響;
          --fields-enclosed- by= char
            指定文本文件中數(shù)據(jù)的記錄時(shí)以什么括起的, 很多情況下數(shù)據(jù)以雙引號(hào)括起。 默認(rèn)的情況下數(shù)據(jù)是沒有被字符括起的。
            --fields-terminated- by=char
            指定各個(gè)數(shù)據(jù)的值之間的分隔符,在句號(hào)分隔的文件中,分隔符是句號(hào)。您可以用此選項(xiàng)指定數(shù)據(jù)之間的分隔符。默認(rèn)的分隔符是跳格符

          (Tab)
            --lines-terminated- by=str
            此選項(xiàng)指定文本文件中行與行之間數(shù)據(jù)的分隔字符串 或者字符。 默認(rèn)的情況下mysqlimport以newline為行分隔符。 您可以選擇用一個(gè)字

          符串來替代一個(gè)單個(gè)的字符: 一個(gè)新行或者一個(gè)回車。
            mysqlimport命令常用的選項(xiàng)還有-v 顯示版本(version), -p 提示輸入密碼(password)等。

          --------------------------------------------------------------

          22.常用插入、修改、刪除語句
          插入記錄:insert into teacher s('','glchengang','深圳一中','1976-10-10');
          修改記錄:update mytable set single=′y′ where name=′abccs′;
          刪除記錄:delete from mytable where name=′abc′;

          出現(xiàn): mysql 的提示符,此時(shí)已進(jìn)入mysql的交互操作方式。
          3、退出MySQL操作界面
          在mysql>提示符下輸入quit可以隨時(shí)退出交互操作界面:
          mysql> quit
          Bye
          你也可以用control-D退出。

          4、第一條命令
          mysql> select version(),current_date();
          +----------------+-----------------+
          | version() | current_date() |
          +----------------+-----------------+
          | 3.23.25a-debug | 2001-05-17 |
          +----------------+-----------------+
          1 row in set (0.01 sec)
          mysql>
          此命令要求mysql服務(wù)器告訴你它的版本號(hào)和當(dāng)前日期。嘗試用不同大小寫操作上述命令,看結(jié)果如何。結(jié)果說明mysql命令的大小寫結(jié)果是一致的。
          練習(xí)如下操作:
          mysql>Select (20+5)*4;
          mysql>Select (20+5)*4,sin(pi()/3);
          mysql>Select (20+5)*4 AS Result,sin(pi()/3); (AS: 指定假名為Result)
          <B>5、多行語句</B>
          一條命令可以分成多行輸入,直到出現(xiàn)分號(hào)“;”為止:
          <ccid_nobr>
          <table width="400" border="1" cellspacing="0" cellpadding="2"
          bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
          <tr>
          <td bgcolor="e6e6e6" class="code" style="font-size:9pt">
          <pre><ccid_code> mysql> select
          -> USER()
          -> ,
          -> now()
          ->;
          +--------------------+---------------------+
          | USER() | now() |
          +--------------------+---------------------+
          | ODBC@localhost | 2001-05-1:59:15 |
          +--------------------+---------------------+
          1 row in set (0.06 sec)
          mysql>
          注意中間的逗號(hào)和最后的分號(hào)的使用方法。

          6、一行多命令
          輸入如下命令:
          mysql> SELECT USER(); SELECT NOW();
          +------------------+
          | USER() |
          +------------------+
          | ODBC@localhost |
          +------------------+
          1 row in set (0.00 sec)
          +---------------------+
          | NOW() |
          +---------------------+
          | 2001-05-17 23:06:15 |
          +---------------------+
          1 row in set (0.00 sec)
          mysql>
          注意中間的分號(hào),命令之間用分號(hào)隔開。

          7、顯示當(dāng)前存在的數(shù)據(jù)庫(kù)
          mysql> show databases;
          +----------+
          | Database |
          +----------+
          | mysql |
          | test |
          +----------+
          2 row in set (0.06 sec)
          mysql>

          8、選擇數(shù)據(jù)庫(kù)并顯示當(dāng)前選擇的數(shù)據(jù)庫(kù)
          mysql> USE mysql
          Database changed
          mysql>
          (USE 和 QUIT 命令不需要分號(hào)結(jié)束。)
          mysql> select database();
          +---------------+
          | database() |
          +---------------+
          | mysql |
          +---------------+
          1 row in set (0.00 sec)

          9、顯示當(dāng)前數(shù)據(jù)庫(kù)中存在的表
          mysql> SHOW TABLES;

          10、顯示表(db)的內(nèi)容
          mysql>select * from db;

          11、命令的取消
          當(dāng)命令輸入錯(cuò)誤而又無法改變(多行語句情形)時(shí),只要在分號(hào)出現(xiàn)前就可以用 c來取消該條命令

          mysql> select
          -> user()
          -> c
          mysql>

           
          posted @ 2007-06-01 14:53 changhong 閱讀(221) | 評(píng)論 (0)編輯 收藏

          Linux上備份Oracle數(shù)據(jù)庫(kù)腳本
          # exp-backup.sh# initialize oracle database env variable /home/oracle/oraenv# assign current date to variable rq# 注意:定義rq變量用的單引號(hào)是tab鍵上面的~鍵。 rq=`date +"%y%m%d"`# export whole database exp expuser/web2dump5@ctgpcweb parfile=./export.par file=/backup/db_1634_$rq.dmp log=./db_1634_$rq.log

          會(huì)發(fā)送和抄送郵件的MySQL數(shù)據(jù)庫(kù)備份腳本
          backupDB_then_mail_it.sh


          #!/bin/bash

          echo Delete last arthive file\(s\) ...
          rm DB_BACKUP.sql.gz

          echo Backup MySQL DB\(c156948_wbj123Drupal\) ...
          mysqldump --user=c156948admin --password=xxxxxxx --host=mysql4-c c156948_wbj123Drupal | gzip > DB_BACKUP.sql.gz

          echo Mail it to xxxxxx@gmail.com ...
          uuencode DB_BACKUP.sql.gz DB_BACKUP.sql.gz | mail -s "Drupal DB BACKUP of wbj123.com" -c xxxxxxx@shtel.net.cn xxxxxx@gmail.com

          解釋如下:
          先刪掉上次備份的舊的備份文件
          再備份MySQL數(shù)據(jù)庫(kù)
          再把數(shù)據(jù)庫(kù)的備份文件Email到兩個(gè)郵箱中

          若不要抄送郵件,就改用下面這段

          echo Mail it to xxx@yyyyyy.com with short title ...
          uuencode DB_BACKUP.sql.gz DB.gz | mail -s "DB" xxx@yyyyyy.com
          
          posted @ 2007-05-23 20:12 changhong 閱讀(260) | 評(píng)論 (0)編輯 收藏

          導(dǎo)航

          <2007年5月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          統(tǒng)計(jì)

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章檔案

          相冊(cè)

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 台北市| 鹤峰县| 齐齐哈尔市| 新野县| 牟定县| 海南省| 孙吴县| 大新县| 抚顺市| 江永县| 盐源县| 安达市| 舒城县| 辽阳市| 内黄县| 贞丰县| 聂拉木县| 扶风县| 镇远县| 永兴县| 内黄县| 辽宁省| 体育| 绥阳县| 六盘水市| 徐闻县| 兴化市| 曲阳县| 荔浦县| 乌兰浩特市| 泸溪县| 五大连池市| 昌吉市| 光泽县| 绿春县| 称多县| 平度市| 噶尔县| 华坪县| 科技| 双城市|