[oracle@zhongwc1 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Wed Jan 23 17:02:01 2013 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SQL> set lines 200 SQL> select instance_name,host_name from v$instance; INSTANCE_NAME HOST_NAME ---------------- ---------------------------------------------------------------- zhongwc1 zhongwc1.oracle.com SQL> select instance_name,host_name from gv$instance; INSTANCE_NAME HOST_NAME ---------------- ---------------------------------------------------------------- zhongwc1 zhongwc1.oracle.com zhongwc2 zhongwc2.oracle.com SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ NO SQL> show release release 1102000300 SQL> alter database flashback on; Database altered. SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ YES SQL> conn zwc Enter password: Connected. SQL> create table t_zhongwc as select * from dba_objects; Table created. SQL> select count(*) from t_zhongwc; COUNT(*) ---------- 75289 SQL>
记录当前的scn(oracle11gR2可以在open状态flashback on)
SQL> select current_scn from v$database; CURRENT_SCN ----------- 1395475
截断t_zhongwc表
SQL> truncate table t_zhongwc; Table truncated. SQL> select count(*) from t_zhongwc; COUNT(*) ---------- 0
开始执行闪回,关闭所有实例,启动zhongwc1到mount,闪回到scn 1395475,以只读模式打开验证
[oracle@zhongwc1 ~]$ srvctl stop database -d zhongwc [oracle@zhongwc1 ~]$ su - grid -c "crsctl stat res -t" Password: -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.CRS.dg ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 ora.DATADG.dg ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 ora.FRADG.dg ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 ora.LISTENER.lsnr ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 ora.asm ONLINE ONLINE zhongwc1 Started ONLINE ONLINE zhongwc2 Started ora.gsd OFFLINE OFFLINE zhongwc1 OFFLINE OFFLINE zhongwc2 ora.net1.network ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 ora.ons ONLINE ONLINE zhongwc1 ONLINE ONLINE zhongwc2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE zhongwc1 ora.cvu 1 ONLINE ONLINE zhongwc1 ora.oc4j 1 ONLINE ONLINE zhongwc1 ora.scan1.vip 1 ONLINE ONLINE zhongwc1 ora.zhongwc.db 1 OFFLINE OFFLINE Instance Shutdown 2 OFFLINE OFFLINE Instance Shutdown ora.zhongwc1.vip 1 ONLINE ONLINE zhongwc1 ora.zhongwc2.vip 1 ONLINE ONLINE zhongwc2 [oracle@zhongwc1 ~]$
[oracle@zhongwc1 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Wed Jan 23 17:22:40 2013 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount ORACLE instance started. Total System Global Area 1269366784 bytes Fixed Size 2227984 bytes Variable Size 889192688 bytes Database Buffers 369098752 bytes Redo Buffers 8847360 bytes Database mounted. SQL> flashback database to scn 1395475; Flashback complete. SQL> alter database open read only; Database altered. SQL> conn zwc Enter password: Connected. SQL> select count(*) from t_zhongwc; COUNT(*) ---------- 75289
resetlogs打开数据库,启动zhongwc2
SQL> shutdown immediate ORA-01031: insufficient privileges SQL> conn / as sysdba Connected. SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 1269366784 bytes Fixed Size 2227984 bytes Variable Size 889192688 bytes Database Buffers 369098752 bytes Redo Buffers 8847360 bytes Database mounted. SQL> alter database open resetlogs; Database altered. SQL> !srvctl start instance -d zhongwc -i zhongwc2 SQL> col host_name format a20 SQL> set lines 300 SQL> select INSTANCE_NAME,HOST_NAME,VERSION,STARTUP_TIME,STATUS,ACTIVE_STATE,INSTANCE_ROLE,DATABASE_STATUS from gv$INSTANCE; INSTANCE_NAME HOST_NAME VERSION STARTUP_TIME STATUS ACTIVE_ST INSTANCE_ROLE DATABASE_STATUS ---------------- -------------------- ----------------- ----------------------- ------------ --------- ------------------ ----------------- zhongwc1 zhongwc1.oracle.com 11.2.0.3.0 23-JAN-2013 17:30:37 OPEN NORMAL PRIMARY_INSTANCE ACTIVE zhongwc2 zhongwc2.oracle.com 11.2.0.3.0 23-JAN-2013 17:34:30 OPEN NORMAL PRIMARY_INSTANCE ACTIVE
SQL> select to_char(scn_to_timestamp(1395475),'yyyy-mm-dd hh24:mi:ss') time_stamp from dual; TIME_STAMP ------------------- 2013-01-23 17:14:05 SQL> flashback database to timestamp to_timestamp('2013-01-23 17:14:05','yyyy-mm-dd hh24:mi:ss'); flashback database to timestamp to_timestamp('2013-01-23 17:14:05','yyyy-mm-dd hh24:mi:ss') * ERROR at line 1: ORA-38757: Database must be mounted and not open to FLASHBACK.
一、查看MySQL运行情况
SHOW STATUS;
二、查看INNODB数据库引擎运行状态
SHOW ENGINE INNODB STATUS;
三、查看当前正在进行的进程,对于有锁表等情况的排查很有用处
SHOW PROCESSLIST; 默认显示前100条
SHOW FULL PROCESSLIST; 显示所有
四、查看MySQL的配置参数
SHOW VARIABLES;
五、查看当前已经被打开的表列表
SHOW OPEN TABLES;
注意:一般情况下,打开MySQL的慢查询记录同样有利于排查,如何开启慢查询,请点击。
附1 SHOW STATUS;关键结果释义
Aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量。
Aborted_connects 尝试已经失败的MySQL服务器的连接的次数。
Connections 试图连接MySQL服务器的次数。
Created_tmp_tables 当执行语句时,已经被创造了的隐含临时表的数量。
Delayed_insert_threads 正在使用的延迟插入处理器线程的数量。
Delayed_writes 用INSERT DELAYED写入的行数。
Delayed_errors 用INSERT DELAYED写入的发生某些错误(可能重复键值)的行数。
Flush_commands 执行FLUSH命令的次数。
Handler_delete 请求从一张表中删除行的次数。
Handler_read_first 请求读入表中第一行的次数。
Handler_read_key 请求数字基于键读行。
Handler_read_next 请求读入基于一个键的一行的次数。
Handler_read_rnd 请求读入基于一个固定位置的一行的次数。
Handler_update 请求更新表中一行的次数。
Handler_write 请求向表中插入一行的次数。
Key_blocks_used 用于关键字缓存的块的数量。
Key_read_requests 请求从缓存读入一个键值的次数。
Key_reads 从磁盘物理读入一个键值的次数。
Key_write_requests 请求将一个关键字块写入缓存次数。
Key_writes 将一个键值块物理写入磁盘的次数。
Max_used_connections 同时使用的连接的最大数目。
Not_flushed_key_blocks 在键缓存中已经改变但是还没被清空到磁盘上的键块。
Not_flushed_delayed_rows 在INSERT DELAY队列中等待写入的行的数量。
Open_tables 打开表的数量。
Open_files 打开文件的数量。
Open_streams 打开流的数量(主要用于日志记载)
Opened_tables 已经打开的表的数量。
Questions 发往服务器的查询的数量。
Slow_queries 要花超过long_query_time时间的查询数量。
Threads_connected 当前打开的连接的数量。
Threads_running 不在睡眠的线程数量。
Uptime 服务器工作了多少秒。
提升性能的建议:
1.如果opened_tables太大,应该把my.cnf中的table_cache变大
2.如果Key_reads太大,则应该把my.cnf中key_buffer_size变大.可以用Key_reads/Key_read_requests计算出cache失败率
3.如果Handler_read_rnd太大,则你写的SQL语句里很多查询都是要扫描整个表,而没有发挥索引的键的作用
4.如果Threads_created太大,就要增加my.cnf中thread_cache_size的值.可以用Threads_created/Connections计算cache命中率
5.如果Created_tmp_disk_tables太大,就要增加my.cnf中tmp_table_size的值,用基于内存的临时表代替基于磁盘的
附2 SHOW PROCESSLIST;结果释义
id列:一个标识,你要kill 一个语句的时候很有用。
user列: 显示当前用户,如果不是root,这个命令就只显示你权限范围内的sql语句。
host列:显示这个语句是从哪个ip 的哪个端口上发出的。可用来追踪出问题语句的用户。
db列:显示这个进程目前连接的是哪个数据库。
command列:显示当前连接的执行的命令,一般就是休眠(sleep),查询(query),连接(connect)。
time列:此这个状态持续的时间,单位是秒。
state列:显示使用当前连接的sql语句的状态,很重要的列,后续会有所有的状态的描述,请注意,state只是语句执行中的某一个状态,一个sql语句,已查询为例,可能需要经过copying to tmp table,Sorting result,Sending data等状态才可以完成。
info列:显示这个sql语句,因为长度有限,所以长的sql语句就显示不全,但是一个判断问题语句的重要依据。
state列具体释义:
Checking table 正在检查数据表(这是自动的)。
Closing tables 正在将表中修改的数据刷新到磁盘中,同时正在关闭已经用完的表。这是一个很快的操作,如果不是这样的话,就应该确认磁盘空间是否已经满了或者磁盘是否正处于重负中。
Connect Out 复制从服务器正在连接主服务器。
Copying to tmp table on disk 由于临时结果集大于 tmp_table_size,正在将临时表从内存存储转为磁盘存储以此节省内存。
Creating tmp table 正在创建临时表以存放部分查询结果。
deleting from main table 服务器正在执行多表删除中的第一部分,刚删除第一个表。
deleting from reference tables 服务器正在执行多表删除中的第二部分,正在删除其他表的记录。
Flushing tables 正在执行 FLUSH TABLES,等待其他线程关闭数据表。
Killed 发送了一个kill请求给某线程,那么这个线程将会检查kill标志位,同时会放弃下一个kill请求。MySQL会在每次的主循环中检查kill标志位,不过有些情况下该线程可能会过一小段才能死掉。如果该线程程被其他线程锁住了,那么kill请求会在锁释放时马上生效。
Locked 被其他查询锁住了。
Sending data 正在处理 SELECT 查询的记录,同时正在把结果发送给客户端。
Sorting for group 正在为 GROUP BY 做排序。
Sorting for order 正在为 ORDER BY 做排序。
Opening tables 这个过程应该会很快,除非受到其他因素的干扰。例如,在执 ALTER TABLE 或 LOCK TABLE 语句行完以前,数据表无法被其他线程打开。 正尝试打开一个表。
Removing duplicates 正在执行一个 SELECT DISTINCT 方式的查询,但是MySQL无法在前一个阶段优化掉那些重复的记录。因此,MySQL需要再次去掉重复的记录,然后再把结果发送给客户端。
Reopen table 获得了对一个表的锁,但是必须在表结构修改之后才能获得这个锁。已经释放锁,关闭数据表,正尝试重新打开数据表。
Repair by sorting 修复指令正在排序以创建索引。
Repair with keycache 修复指令正在利用索引缓存一个一个地创建新索引。它会比 Repair by sorting 慢些。
Searching rows for update 正在讲符合条件的记录找出来以备更新。它必须在 UPDATE 要修改相关的记录之前就完成了。
Sleeping 正在等待客户端发送新请求.
System lock 正在等待取得一个外部的系统锁。如果当前没有运行多个 mysqld 服务器同时请求同一个表,那么可以通过增加 –skip-external-locking参数来禁止外部系统锁。
Upgrading lock INSERT DELAYED 正在尝试取得一个锁表以插入新记录。
Updating 正在搜索匹配的记录,并且修改它们。
User Lock 正在等待 GET_LOCK()。
Waiting for tables 该线程得到通知,数据表结构已经被修改了,需要重新打开数据表以取得新的结构。然后,为了能的重新打开数据表,必须等到所有其他线程关闭这个表。
以下几种情况下会产生这个通知:FLUSH TABLES tbl_name, ALTERTABLE, RENAME TABLE, REPAIR TABLE, ANALYZE TABLE, 或 OPTIMIZE TABLE。
waiting for handler insert INSERT DELAYED 已经处理完了所有待处理的插入操作,正在等待新的请求。 大部分状态对应很快的操作,只要有一个线程保持同一个状态好几秒钟,那么可能是有问题发生了,需要检查一下。
还有其它的状态没在上面中列出来,不过它们大部分只是在查看服务器是否有存在错误是才用得着。
本文链接
into table db.new
fields terminated by ':' //列的分割符
lines terminated by '\n'; //行的分割符
load data local infile '/tmp/test.txt'
into table db.user //表列类似/etc/passwd,自己动手建吧!
fields terminated by ':'
lines terminated by '\n'
(username, password, uid, gid, common, home_dir, shell) ;
从数据库导出到文档 mysql> select username,password,uid from db.new into outfile '/tmp/tao.txt'
fields terminated by '#'
lines terminated by '\n';
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mysql之load dataName: 'LOAD DATA'
Description:
Syntax:
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[CHARACTER SET charset_name]
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
[IGNORE number {LINES | ROWS}]
[(col_name_or_user_var,...)]
[SET col_name = expr,...]
The LOAD DATA INFILE statement reads rows from a text file into a table
at a very high speed. The file name must be given as a literal string.
LOAD DATA INFILE is the complement of SELECT ... INTO OUTFILE. (See
http://dev.mysql.com/doc/refman/5.5/en/select-into.html.) To write data
from a table to a file, use SELECT ... INTO OUTFILE. To read the file
back into a table, use LOAD DATA INFILE. The syntax of the FIELDS and
LINES clauses is the same for both statements. Both clauses are
optional, but FIELDS must precede LINES if both are specified.
For more information about the efficiency of INSERT versus LOAD DATA
INFILE and speeding up LOAD DATA INFILE, see
http://dev.mysql.com/doc/refman/5.5/en/insert-speed.html.
The character set indicated by the character_set_database system
variable is used to interpret the information in the file. SET NAMES
and the setting of character_set_client do not affect interpretation of
input. If the contents of the input file use a character set that
differs from the default, it is usually preferable to specify the
character set of the file by using the CHARACTER SET clause. A
character set of binary specifies "no conversion."
LOAD DATA INFILE interprets all fields in the file as having the same
character set, regardless of the data types of the columns into which
field values are loaded. For proper interpretation of file contents,
you must ensure that it was written with the correct character set. For
example, if you write a data file with mysqldump -T or by issuing a
SELECT ... INTO OUTFILE statement in mysql, be sure to use a
--default-character-set option with mysqldump or mysql so that output
is written in the character set to be used when the file is loaded with
LOAD DATA INFILE.
*Note*: It is not possible to load data files that use the ucs2, utf16,
or utf32 character set.
The character_set_filesystem system variable controls the
interpretation of the file name.
You can also load data files by using the mysqlimport utility; it
operates by sending a LOAD DATA INFILE statement to the server. The
--local option causes mysqlimport to read data files from the client
host. You can specify the --compress option to get better performance
over slow networks if the client and server support the compressed
protocol. See http://dev.mysql.com/doc/refman/5.5/en/mysqlimport.html.
If you use LOW_PRIORITY, execution of the LOAD DATA statement is
delayed until no other clients are reading from the table. This affects
only storage engines that use only table-level locking (such as MyISAM,
MEMORY, and MERGE).
If you specify CONCURRENT with a MyISAM table that satisfies the
condition for concurrent inserts (that is, it contains no free blocks
in the middle), other threads can retrieve data from the table while
LOAD DATA is executing. Using this option affects the performance of
LOAD DATA a bit, even if no other thread is using the table at the same
time.
Prior to MySQL 5.5.1, CONCURRENT was not replicated when using
statement-based replication (see Bug #34628). However, it is replicated
when using row-based replication, regardless of the version. See
http://dev.mysql.com/doc/refman/5.5/en/replication-features-load-data.h
tml, for more information.
The LOCAL keyword, if specified, is interpreted with respect to the
client end of the connection:
o If LOCAL is specified, the file is read by the client program on the
client host and sent to the server. The file can be given as a full
path name to specify its exact location. If given as a relative path
name, the name is interpreted relative to the directory in which the
client program was started.
When using LOCAL with LOAD DATA, a copy of the file is created in the
server's temporary directory. This is not the directory determined by
the value of tmpdir or slave_load_tmpdir, but rather the operating
system's temporary directory, and is not configurable in the MySQL
Server. (Typically the system temporary directory is /tmp on Linux
systems and C:\WINDOWS\TEMP on Windows.) Lack of sufficient space for
the copy in this directory can cause the LOAD DATA LOCAL statement to
fail.
o If LOCAL is not specified, the file must be located on the server
host and is read directly by the server. The server uses the
following rules to locate the file:
o If the file name is an absolute path name, the server uses it as
given.
o If the file name is a relative path name with one or more leading
components, the server searches for the file relative to the
server's data directory.
o If a file name with no leading components is given, the server
looks for the file in the database directory of the default
database.
Note that, in the non-LOCAL case, these rules mean that a file named as
./myfile.txt is read from the server's data directory, whereas the file
named as myfile.txt is read from the database directory of the default
database. For example, if db1 is the default database, the following
LOAD DATA statement reads the file data.txt from the database directory
for db1, even though the statement explicitly loads the file into a
table in the db2 database:
LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
Windows path names are specified using forward slashes rather than
backslashes. If you do use backslashes, you must double them.
For security reasons, when reading text files located on the server,
the files must either reside in the database directory or be readable
by all. Also, to use LOAD DATA INFILE on server files, you must have
the FILE privilege. See
http://dev.mysql.com/doc/refman/5.5/en/privileges-provided.html. For
non-LOCAL load operations, if the secure_file_priv system variable is
set to a nonempty directory name, the file to be loaded must be located
in that directory.
http://dev.mysql.com/doc/refman/5.5/en/load-data.html
小分享两个数据库之间相互导入,需要字符集一样!如果是英文的字符集,则无需关注字符集! 字符集相关,分享一个Oracal大师的研究!太厉害了!
(windows \n\r , linux \n ========>shell>yum install -y
dos2unix)
shell>dos2unix test.txt --->转换为 unix 格式
shell>unix2dos test.t