[Cassandra] cassandra使用nodetool decommission之后发现丢失数据的解决办法


1、故事背景

当某一个节点执行nodetool decommission时,这个节点会被退役,该节点上的数据会流到其他正在活动的节点,但是该节点上的数据不会被清除,会保留在数据文件下。当发现剩余的的节点下未完全同步该退役的节点,可使用以下办法尝试去恢复数据。
被退役节点为(A),活动节点为(B)

2、尝试重新启动A节点,报错如下:

1
2
3
4
5
6
This node was decommissioned and will not rejoin the ring unless cassandra.override_decommission=true has been set, or all existing data is removed and th
e node is bootstrapped again
Fatal configuration error; unable to start server. See log for stacktrace.
ERROR [main] 2019-02-12 06:03:30,000 CassandraDaemon.java:749 - Fatal configuration error
org.apache.cassandra.exceptions.ConfigurationException: This node was decommissioned and will not rejoin the ring unless cassandra.override_decommission=t
rue has been set, or all existing data is removed and the node is bootstrapped again

3、报错提示要么删除目录下的所有数据,要么使用override_decommission=true参数启动,下面以添加参数启动,启动正常,启动命令:

1
cassandra -Dcassandra.override_decommission=true -R

4、但是启动完成之后发现,只存在system相关的keyspaces,其它数据没办法加载出来

1
2
cdax@cqlsh> desc keyspaces;
system_auth system_distributed system_schema system system_traces

5、因为要恢复的keyspace–“test”数据目录存在,尝试使用sstableloader去加载数据文件:

1
sstableloader -d 127.0.0.1 /tmp/test/trade_event-8d5d68508fe211e88a9ca166a7412712

6、提示当前节点下不存在test.trade_event表,需要自己先手动创建该表,去B节点上执行desc test_trade_event,查看建表语句,重新在A节点创建该表。

创建完成之后再次执行

1
sstableloader -d 127.0.0.1 /tmp/test/trade_event-8d5d68508fe211e88a9ca166a7412712

7、文件下的数据全部导入test.trade_event表下面,然后使用copy将该表下面的数据全部导入到某一单独文件下:

1
copy trade_event to '/tmp/trade_event.sql' with header=true;

8、恢复之前须知:

copy from操作并不会覆盖掉以前所有旧的数据,只会将A节点存在,B节点不存的数据导入到B节点。但是如果是B和A两个节点主键相同,其他字段数据不同,使用copy from的情况下,A节点的数据会覆盖掉B节点的数据。
因为我们decommission节点之后,启动应用发现缺少数据,导致应用无法起来,这种情况下B节点没有最新数据插入,因此可以执行copy from操作。如果无法确定B节点是否有新的数据插入,建议先根据某个表对应的时间戳先校验,确保没有最新数据插入的情况下,再使用上面的方法执行。

9、导出完成之后,将导出的文件拷贝到B节点,之后再B节点上执行copy from操作将数据恢复:

1
COPY trade_event FROM '/home/test/trade_event.sql' WITH HEADER = TRUE ;

点击阅读

[Mysql] SELECT ... INTO OUTFILE 'file_name'将查询到的数据写入文件


1、生成的文件会在server主机端,因此mysql必须有指定file_name文件所在目录的权限,另外file_name文件必须是不存在的,防止其他数据文件被破坏。

例如:

1
select * from admin into outfile 'd:/admin.xls'

2、使用SELECT … INTO OUTFILE ‘file_name’方式导出数据文件是受参数secure_file_priv控制的,不同值管理着数据是否能正常导出

2.1、secure_file_priv参数值(静态参数,修改必须重启mysql):
1
2
3
如果该值为空,对导出没有限制,这是不安全的设置
如果该值指定了某一个目录,那么导入导出数据操作只能在这个目录下操作,而且指定的目录必须是存在的,mysql服务不能够自动创建。
如果该值为null,那么当前数据库不允许导入导出
2.2、查看参数值
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@db 02:48:  [(none)]> show variables like '%secure_file%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | NULL |
+------------------+-------+
1 row in set (0.00 sec)
root@db 02:48: [test]> select * from t1;
+----+
| c1 |
+----+
| 1 |
+----+
1 row in set (0.00 sec)

在值为null的时候是不允许导出数据的

1
2
root@db 02:48:  [test]> select * from t1 into outfile '/tmp/t1.xls';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
2.3、修改secure_file_priv的值

在my.cnf配置文件下添加

1
secure_file_priv=''

或者

1
secure_file_priv='/tmp'

并重启数据库,指定的目录必须存在,否则无法启动数据库
不能直接通过set global参数修改,修改会报错:

1
2
root@db 02:49:  [test]> set global secure_file_priv='/data/test';
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable

重启完之后,查看secure参数:

1
2
3
4
5
6
7
root@db 03:08:  [(none)]> show variables like '%secure_file%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | /tmp/ |
+------------------+-------+
1 row in set (0.02 sec)

3、导出查询数据

1
2
root@db 04:16:  [test]> select * from mysql.user into outfile '/tmp/user.xls';
Query OK, 5 rows affected (0.01 sec)

如果导出的目录不是secure_file_priv指定的目录,报错:

1
2
root@db 00:17:  [test]> select * from t1 into outfile '/data/t1.xls';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

点击阅读

[Mysql] create table ... data directory指定外部数据目录(单表文件表空间)


1、使用create table … data directory

1
2
3
4
5
6
7
8
9
10
root@db 18:15:  [(none)]> use test
Database changed
root@db 18:16: [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
| t4 |
+----------------+
2 rows in set (0.00 sec)

指定的目录对于mysql的用户来说一定要有访问权限

1
2
[root@dax-mysql-master test]# ll -d /tmp/
drwxrwxrwt. 10 root root 4096 2月 11 20:54 /tmp/

执行创建表语句

1
2
root@db 18:41:  [test]> CREATE TABLE t2 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/tmp/';
Query OK, 0 rows affected (0.60 sec)

表创建完成之后,会在directory对应的目录下创建表对应的schema的目录,并在schema的目录下生成.ibd表文件

1
2
[root@dax-mysql-master test]# ll /tmp/test/t2*
-rw-r----- 1 mysql mysql 98304 2月 11 18:41 /tmp/test/t2.ibd

在mysql的数据目录下会生成.frm文件和.isl文件

1
2
3
[root@dax-mysql-master test]# ll /data/mysql/data/test/t2*
-rw-r----- 1 mysql mysql 8556 2月 11 18:41 /data/mysql/data/test/t2.frm
-rw-r----- 1 mysql mysql 16 2月 11 18:41 /data/mysql/data/test/t2.isl

2、使用create table … tablespace .. data directory

1
2
3
4
5
6
7
root@db 18:41:  [test]>  CREATE TABLE t3 (c1 INT PRIMARY KEY) TABLESPACE = innodb_file_per_table DATA DIRECTORY = '/tmp';
Query OK, 0 rows affected (0.33 sec)
[root@dax-mysql-master test]# ll /tmp/test/t3*
-rw-r----- 1 mysql mysql 98304 2月 11 22:16 /tmp/test/t3.ibd
[root@dax-mysql-master test]# ll /data/mysql/data/test/t3*
-rw-r----- 1 mysql mysql 8556 2月 11 22:16 /data/mysql/data/test/t3.frm
-rw-r----- 1 mysql mysql 16 2月 11 22:16 /data/mysql/data/test/t3.isl

执行结果与章节1相同。

点击阅读

[Mysql] general-tablespace详解


0、功能介绍
1
2
3
4
5
6
1、类似于系统表空间,一般表空间也是共享表空间,可以存储多个表的数据
2、一般表空间相比于单表文件表空间有潜在的内存优势。在表空间的生命周期里,服务端可以在内存中保持表空间的元数据。多个表在较少的一般表空间内消耗的内存相比于相同数量的表在单表文件表空间所占用的内存要少的多。
3、一般表空间的存放目录可以是放在mysql的数据目录,也可以单独存放于其他目录。将数据文件放在mysql数据目录以外,这样就可以自己管理单独管理表的性能,对特定的表设置raid、drbd,或者使用特殊的磁盘。
4、一般表空间支持antelope和barracuda文件格式,因此支持所有的表行格式和相关特性。因为支持上面两种文件格式,因此一般表空间不依赖与innodb_file_format和innodb_file_per_table的设置,这些参数的设置对于一般表空间没有影响。
5、create tables语句时可以使用tablespace参数指定放到一遍表空间、单表文件表空间还是系统表空间
6、使用alter table移动表时,可以添加tablespace参数用于将表在一般表空间、单表文件表空间、系统表空间之间移动。

1、创建一般表空间

1.1、创建表空间语法
1
CREATE TABLESPACE tablespace_name ADD DATAFILE 'file_name' [FILE_BLOCK_SIZE = value] [ENGINE [=] engine_name]
1.2、创建在mysql数据目录下的一般表空间
1
2
root@db 22:19:  [information_schema]> CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' Engine=InnoDB;
Query OK, 0 rows affected (0.28 sec)

查看创建成功后的表空间信息:

1
2
3
4
5
6
7
root@db 22:19:  [information_schema]> select * from innodb_sys_tablespaces where name='ts1';
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
| SPACE | NAME | FLAG | FILE_FORMAT | ROW_FORMAT | PAGE_SIZE | ZIP_PAGE_SIZE | SPACE_TYPE | FS_BLOCK_SIZE | FILE_SIZE | ALLOCATED_SIZE |
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
| 678 | ts1 | 2048 | Any | Any | 16384 | 0 | General | 4096 | 65536 | 32768 |
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
1 row in set (0.00 sec)

删除创建的表空间:

1
2
root@db 22:19:  [information_schema]> drop tablespace ts1;
Query OK, 0 rows affected (0.20 sec)
1.3、创建在数据目录以外的一般表空间(切记如果是主从或者是mgr集群模式,其他节点也要执行创建目录操作,否则会导致事务异常,集群崩溃)
1
2
3
4
5
6
7
8
9
10
shell> mkdir -p /tmp/test
shell> chown mysql.mysql /tmp/test
mysql> CREATE TABLESPACE `ts1` ADD DATAFILE '/tmp/test/ts1.ibd' Engine=InnoDB;
mysql> select * from innodb_sys_tablespaces where name='ts1';
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
| SPACE | NAME | FLAG | FILE_FORMAT | ROW_FORMAT | PAGE_SIZE | ZIP_PAGE_SIZE | SPACE_TYPE | FS_BLOCK_SIZE | FILE_SIZE | ALLOCATED_SIZE |
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
| 680 | ts1 | 2048 | Any | Any | 16384 | 0 | General | 4096 | 65536 | 32768 |
+-------+------+------+-------------+------------+-----------+---------------+------------+---------------+-----------+----------------+
1 row in set (0.01 sec)

创建完成之后会在mysql数据目录下生成一个.isl的文件

1
2
[root@dax-mysql-master data]# ll /data/mysql/data/ts1*
-rw-r----- 1 mysql mysql 17 2月 10 22:32 /data/mysql/data/ts1.isl

在创建的外部数据目录下生成了创建的ibd文件

1
2
[root@dax-mysql-master data]# ll /tmp/test/ts1*
-rw-r----- 1 mysql mysql 65536 2月 10 22:32 /tmp/test/ts1.ibd
1.4、使用create tablespace创建一般表空间时,如果默认参数(default_storage_engine=InnoDB)没有被指定,一定要手动在语句末尾加上ENGINE = InnoDB 子句。

2、增加表到一般表空间

2.1、使用create table
1
CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1;

查看表所属的表空间

1
2
3
4
5
6
7
8
9
root@db 23:08:  [test]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='test/t1';
+----------+---------+-------+------+
| table_id | name | space | name |
+----------+---------+-------+------+
| 970 | test/t1 | 680 | ts1 |
+----------+---------+-------+------+
1 row in set (0.01 sec)
root@db 23:06: [test]> CREATE TABLE test.t1 (c1 INT PRIMARY KEY) TABLESPACE ts1;
Query OK, 0 rows affected (0.55 sec)
2.2、使用alter table移动表到一般表空间
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@db 23:11:  [test]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='aaaa/test';
+----------+-----------+-------+-----------+
| table_id | name | space | name |
+----------+-----------+-------+-----------+
| 761 | aaaa/test | 476 | aaaa/test |
+----------+-----------+-------+-----------+
1 row in set (0.00 sec)
root@db 23:11: [test]> alter table aaaa.test tablespace ts1;
Query OK, 0 rows affected (0.92 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@db 23:12: [test]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='aaaa/test';
+----------+-----------+-------+------+
| table_id | name | space | name |
+----------+-----------+-------+------+
| 971 | aaaa/test | 680 | ts1 |
+----------+-----------+-------+------+
1 row in set (0.01 sec)

修改完成之后,在aaaa的数据目录下的test.ibd文件就不存在了,只剩下了test.frm文件

3、关于压缩表和general tablespace的限制

对于包含压缩表的general tablespace,在创建的时候必须指定FILE_BLOCK_SIZE参数,该值必须是合理的压缩页大小与innodb_page_size的值相关联,同时创建压缩表是的key_block_size必须等于FILE_BLOCK_SIZ/1024。例如,如果innodb_page_size=16k、file_block_size=8k,key_block_size的值必须是8.
关于innodb_page_size、file_block_size、key_block_size的大小的设置,官方文档有详解介绍,点击此处查看详情

下面举例创建压缩表

1
2
3
4
5
6
7
8
mysql> CREATE TABLESPACE `ts2` ADD DATAFILE 'ts2.ibd' FILE_BLOCK_SIZE = 8192 Engine=InnoDB;(在这里执行的时候,没有注意主从,在从库执行的时候也成功了,并且同步到了主库上)
mysql> CREATE TABLE test.t4 (c1 INT PRIMARY KEY) TABLESPACE ts2 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
root@db 00:01: [test]> select a.table_id,a.name,a.row_format,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='test/t4';
+----------+---------+------------+-------+------+
| table_id | name | row_format | space | name |
+----------+---------+------------+-------+------+
| 973 | test/t4 | Compressed | 681 | ts2 |
+----------+---------+------------+-------+------+

如果创建的general tablespace没有指定file_block_size,会使用默认的innodb_page_size,但是当这两个值相等时,该表空间将仅支持(COMPACT, REDUNDANT, and DYNAMIC row formats),不支持uncompressed 格式。

4、移动表

4.1、从单表文件表空间、系统表空间移动到general tablespace
1
ALTER TABLE tbl_name TABLESPACE [=] tablespace_name;

参考2.2章节

4.2、从单表文件表空间、一般表空间移动到系统表空间

ALTER TABLE tbl_name TABLESPACE [=] innodb_system;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@db 01:09:  [test]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='aaaa/test';
+----------+-----------+-------+------+
| table_id | name | space | name |
+----------+-----------+-------+------+
| 971 | aaaa/test | 680 | ts1 |
+----------+-----------+-------+------+
1 row in set (0.01 sec)
root@db 01:09: [test]> alter table aaaa.test tablespace = innodb_system;
Query OK, 0 rows affected (0.78 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@db 01:34: [aaaa]> select * from information_schema.innodb_sys_tables where name='aaaa/test';
+----------+-----------+------+--------+-------+-------------+------------+---------------+------------+
| TABLE_ID | NAME | FLAG | N_COLS | SPACE | FILE_FORMAT | ROW_FORMAT | ZIP_PAGE_SIZE | SPACE_TYPE |
+----------+-----------+------+--------+-------+-------------+------------+---------------+------------+
| 976 | aaaa/test | 161 | 4 | 0 | Barracuda | Dynamic | 0 | System |
+----------+-----------+------+--------+-------+-------------+------------+---------------+------------+
1 row in set (0.00 sec)
4.3、从系统表空间或者general table移动到单表文件表空间
1
ALTER TABLE tbl_name TABLESPACE [=] innodb_file_per_table;
1
2
3
4
5
6
7
8
9
10
root@db 01:36:  [aaaa]> ALTER TABLE aaaa.test TABLESPACE = innodb_file_per_table;
Query OK, 0 rows affected (0.80 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@db 01:36: [aaaa]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and a.name='aaaa/test';
+----------+-----------+-------+-----------+
| table_id | name | space | name |
+----------+-----------+-------+-----------+
| 977 | aaaa/test | 682 | aaaa/test |
+----------+-----------+-------+-----------+
1 row in set (0.01 sec)
4.4、alter table tablespace操作会重建整个表,并且不支持从临时表移动到永久表,

5、删除general tablespace

在删除general tablespace之前要删除这个表空间下的所有表,如果强行删除非空表空间,会返回报错。
查看要删除的表空间下面有没有其他库的表

1
2
3
4
5
6
7
8
root@db 17:18:  [aaaa]> select a.table_id,a.name,a.space,b.name from information_schema.innodb_sys_tables a,information_schema.innodb_sys_tablespaces b where a.space=b.space and  b.name='ts1';
+----------+------------+-------+------+
| table_id | name | space | name |
+----------+------------+-------+------+
| 972 | aaaa/test1 | 680 | ts1 |
| 970 | test/t1 | 680 | ts1 |
+----------+------------+-------+------+
2 rows in set (0.00 sec)

强行删除ts1表空间

1
2
root@db 17:18:  [aaaa]> drop tablespace ts1;
ERROR 1529 (HY000): Failed to drop TABLESPACE ts1

6、注意事项

1
2
3
4
5
1、不建议使用表分区在共享表空间,这个特性在5.7.24版本是支持的,但是会在未来被移除。
2、对于不同的physical page size的压缩表和非压缩表不能共存于同一个general tablespace
3、不能创建临时general tablespace
4、删除在general tablespace下的表,空间不会释放,只能用于新的innodb数据
5、alter table ... discard tablespace和alter table ... import tablespace对于general tablespace下的表时不支持的

点击阅读

[Oracle] oracle设置用户名密码复杂性校验


1、在$ORACLE_HOME/rdbms/admin/目录下存在一个文件utlpwdmg.sql,里面有默认的配置可以直接执行,也可根据自己的需求修改配置文件再执行该脚本:

1
sql>@?/rdbms/admin/utlpwdmg.sql

2、执行完成之后,再次修改密码使用简单的密码,将提示28003错误:

1
2
3
4
5
6
14:16:23 SYS@ boston> alter user test identified by oracle;
alter user test identified by oracle
*
ERROR at line 1:
ORA-28003: password verification for the specified password failed
ORA-20001: Password length less than 8

3、查看修改后的概要文件下的参数

1
2
3
4
5
6
7
8
9
10
SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';

PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT PASSWORD_LIFE_TIME PASSWORD 180
DEFAULT PASSWORD_REUSE_TIME PASSWORD UNLIMITED
DEFAULT PASSWORD_REUSE_MAX PASSWORD UNLIMITED
DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD VERIFY_FUNCTION_11G
DEFAULT PASSWORD_LOCK_TIME PASSWORD 1
DEFAULT PASSWORD_GRACE_TIME PASSWORD 7

4、现在重置密码的时候,密码还是可以复用的,因为PASSWORD_REUSE_TIME和PASSWORD_REUSE_MAX参数没有限制:

1
2
3
4
5
15:04:58 SYS@ boston> alter user test identified by Testdb123
User altered.
Elapsed: 00:00:00.11
15:06:04 SYS@ boston> alter user test identified by Testdb123;
User altered.

5、下面修改PASSWORD_REUSE_TIME(用户名可以在多长时间之后可以复用)或者密码修改过多少次之后可以复用以前的旧密码(PASSWORD_REUSE_MAX)

,官方文档提示,只修改两个参数中的任意一个,另一个参数为unlimited,结果是用户永远不能复用密码:

5.1、只单独修改PASSWORD_REUSE_TIME
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
15:13:17 SYS@ boston> ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_TIME 1;
Profile altered.
Elapsed: 00:00:00.08
15:13:18 SYS@ boston> SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';

PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT PASSWORD_LIFE_TIME PASSWORD 180
DEFAULT PASSWORD_REUSE_TIME PASSWORD 1
DEFAULT PASSWORD_REUSE_MAX PASSWORD UNLIMITED
DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD VERIFY_FUNCTION_11G
DEFAULT PASSWORD_LOCK_TIME PASSWORD 1
DEFAULT PASSWORD_GRACE_TIME PASSWORD 7
再次修改用户已经提示
15:13:22 SYS@ boston> alter user test identified by Testdb123;
alter user test identified by Testdb123
*
ERROR at line 1:
ORA-28007: the password cannot be reused
Elapsed: 00:00:00.02
5.2、只单独修改PASSWORD_REUSE_MAX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_TIME UNLIMITED;
ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_MAX 5;
ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_TIME UNLIMITED;
Profile altered.
Elapsed: 00:00:00.05
15:19:26 SYS@ boston> ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_MAX 5;
Profile altered.
Elapsed: 00:00:00.03
15:19:26 SYS@ boston> SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';
PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT PASSWORD_LIFE_TIME PASSWORD 180
DEFAULT PASSWORD_REUSE_TIME PASSWORD UNLIMITED
DEFAULT PASSWORD_REUSE_MAX PASSWORD 5
DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD VERIFY_FUNCTION_11G
DEFAULT PASSWORD_LOCK_TIME PASSWORD 1
DEFAULT PASSWORD_GRACE_TIME PASSWORD 7
6 rows selected.
Elapsed: 00:00:00.01
15:19:29 SYS@ boston> alter user test identified by Testdb123;
alter user test identified by Testdb123
*
ERROR at line 1:
ORA-28007: the password cannot be reused
5.3、下面同时修改这两个参数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
15:21:45 SYS@ boston> ALTER PROFILE DEFAULT LIMIT PASSWORD_REUSE_TIME 1;
Profile altered.
Elapsed: 00:00:00.05
15:21:46 SYS@ boston> SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';

PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT PASSWORD_LIFE_TIME PASSWORD 180
DEFAULT PASSWORD_REUSE_TIME PASSWORD 1
DEFAULT PASSWORD_REUSE_MAX PASSWORD 5
DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD VERIFY_FUNCTION_11G
DEFAULT PASSWORD_LOCK_TIME PASSWORD 1
DEFAULT PASSWORD_GRACE_TIME PASSWORD 7
设置一天之后,并且修改5次不同密码之后才能复用之前的密码,下面为了满足要求,修改系统时间:
15:23:00 SYS@ boston> select sysdate from dual;
SYSDATE
-------------------
2019:01:23 15:23:04
[oracle@dax-mysql-slave admin]$ date -s 20190125
date: 无法设置日期: 不允许的操作
2019年 01月 25日 星期五 00:00:00 CST
[oracle@dax-mysql-slave admin]$ exit
登出
[root@dax-mysql-slave ~]# date -s 20190125
2019年 01月 25日 星期五 00:00:00 CST
[root@dax-mysql-slave ~]# su - oracle
上一次登录:三 1月 23 13:44:53 CST 2019pts/2 上
[oracle@dax-mysql-slave ~]$ date
2019年 01月 25日 星期五 00:00:06 CST
[oracle@dax-mysql-slave ~]$ sql
00:00:26 SYS@ boston> select sysdate from dual;
SYSDATE
-------------------
2019:01:25 00:00:34
Elapsed: 00:00:00.00
00:00:34 SYS@ boston> SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';
PROFILE RESOURCE_NAME RESOURCE LIMIT
------------------------------ -------------------------------- -------- ----------------------------------------
DEFAULT PASSWORD_LIFE_TIME PASSWORD 180
DEFAULT PASSWORD_REUSE_TIME PASSWORD 1
DEFAULT PASSWORD_REUSE_MAX PASSWORD 5
DEFAULT PASSWORD_VERIFY_FUNCTION PASSWORD VERIFY_FUNCTION_11G
DEFAULT PASSWORD_LOCK_TIME PASSWORD 1
DEFAULT PASSWORD_GRACE_TIME PASSWORD 7
6 rows selected.
Elapsed: 00:00:00.03
修改5次不同的密码:
00:04:17 SYS@ boston> alter user test identified by Testdb128;
User altered.
Elapsed: 00:00:00.08
00:04:29 SYS@ boston> alter user test identified by Testdb129;
User altered.
Elapsed: 00:00:00.03
00:04:33 SYS@ boston> alter user test identified by Testdb130;
User altered.
Elapsed: 00:00:00.04
00:04:37 SYS@ boston> alter user test identified by Testdb131;
User altered.
Elapsed: 00:00:00.04
00:04:39 SYS@ boston> alter user test identified by Testdb132;
User altered.
修改5次之后再次修改为以前的密码,修改正常:
Elapsed: 00:00:00.04
00:04:40 SYS@ boston> alter user test identified by Testdb123;
User altered.
再次修改为上面修改的新的密码,提示不能复用:
Elapsed: 00:00:00.05
00:04:46 SYS@ boston> alter user test identified by Testdb130;
alter user test identified by Testdb130
*
ERROR at line 1:
ORA-28007: the password cannot be reused
Elapsed: 00:00:00.02
00:04:56 SYS@ boston>

6、还原上面的操作,在oracle下面有一个还原脚本,执行下面命令:

1
sql>@?/rdbms/admin/undopwd.sql

上面的脚本把PASSWORD_LIFE_TIME、PASSWORD_REUSE_TIME等参数改为了unlimitd,但是PASSWORD_VERIFY_FUNCTION的限制函数VERIFY_FUNCTION_11G仍然存在,如果不把这个清空,密码的复杂度校验仍然存在,清空密码复杂度校验执行下面操作:

1
sql>alter profile default limit PASSWORD_VERIFY_FUNCTION null;

点击阅读

[Oracle] 修改oracle用户密码永不过期


1、查看用户有无过期

1
select username,account_status,expiry_date from dba_users;

2、查看用户使用概要文件

1
SELECT username,PROFILE FROM dba_users;

3、查看概要文件密码有效期

1
SELECT * FROM dba_profiles s WHERE s.profile='DEFAULT' AND resource_name like 'PASSWORD%';

4、修改概要文件有效期

1
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

5、再次查看用户过期时间,expiry_date字段已经变为空

1
select username,account_status,expiry_date from dba_users;

6、rac环境在任意一个节点执行即可。

点击阅读

[Mysql] mysql参数NO_AUTO_CREATE_USER


1、sql_mode存在NO_AUTO_CREATE_USER情况下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@db 01:05:  [(none)]> show variables like '%sql_mode%';
+---------------+------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+------------------------------------------------------------------------------------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+---------------+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

root@db 01:05: [(none)]> select host,user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | zabbix |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | zabbix |
+-----------+---------------+
5 rows in set (0.01 sec)

在包含NO_AUTO_CREATE_USER的情况下,使用grant去授权一个不存在的用户,必须要使用identified by参数或者identified with插件指定密码,才能够创建用户并授权成功:

1
2
3
4
root@db 01:07:  [(none)]> grant all privileges on *.* to testuser;
ERROR 1133 (42000): Can't find any matching row in the user table
root@db 01:07: [(none)]> grant all privileges on *.* to testuser identified by 'testuser';
Query OK, 0 rows affected, 1 warning (0.01 sec)

2、sql_mode不存在NO_AUTO_CREATE_USER情况下

1
2
3
4
5
6
7
8
9
10
11
root@db 01:14:  [(none)]> set @@sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION";
Query OK, 0 rows affected, 1 warning (0.00 sec)
root@db 01:17: [(none)]> show variables like '%sql_mode%';
+---------------+----------------------------------------------------------------------------------------------------+
| Variable_name | Value |
+---------------+----------------------------------------------------------------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+---------------+----------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
root@db 01:17: [(none)]> grant all privileges on *.* to testuser1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

没有密码也能够创建该用户,并授权成功,使用该用户没有密码可以直接登录

1
2
3
4
5
6
7
8
9
10
11
12
13
root@db 01:17:  [(none)]> select host,user from mysql.user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | testuser |
| % | testuser1 |
| % | zabbix |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | zabbix |
+-----------+---------------+
7 rows in set (0.00 sec)

3、总结:

1
NO_AUTO_CREATE_USER参数在未来将会被弃用,被弃用的原因是基于对复制安全性的考虑。而基于复制安全性的考虑,对用户进行管理操作的更好方法是使用:CREATE USER IF NOT EXISTS, DROP USER IF EXISTS, 和ALTER USER IF EXISTS而不是grant命令。这些语句可以保证复制的安全性当从库存在和主库的不同权限。

点击阅读

[Sqlserver] Sqlserver2017数据库导入低版本sqlserver2016数据库


1、源库操作

通过sqlserver manager studio登录sqlserver2017,对要备份的库进行操作:tasks–>Generate scripts

点击下一步Next:

可以选择要备份整个库,还是只备份这个库的某个对象,我们这里备份整个库:

点击下一步,点击advanced,进行编辑,将Script for server version修改为要目标库的版本(sqlserver2016),Type of data to script改为Schema and data:

修改备份的路径,点击next:

开始导出数据:

2、目标库操作

数据导出完成之后,将备份的数据拷贝到目标端服务器,目录根据自己需求定义,然后通过management studio登录sqlserver2016数据库(这里安装sqlserver2016的过程中,发现没有自带managerment studio管理软件,需要自己单独安装,sqlserver2016 management studio下载链接,点击此处

登录management studio打开拷贝过来的脚本,修改脚本:
将数据路径和日志路径修改为本地的sqlserver路径,如果database已经建立了,可以把create database参数改为use

点击阅读

[Oracle] oracle修改字符集


0、查看数据库字符集

1)数据库服务器字符集

1
select * from nls_database_parameters;

来源于props$,是表示数据库的字符集。
2)客户端字符集环境

1
select * from nls_instance_parameters;

其来源于v$parameter,表示客户端的字符集的设置,可能是参数文件,环境变量或者是注册表
3)会话字符集环境

1
select * from nls_session_parameters;

来源于v$nls_parameters,表示会话自己的设置,可能是会话的环境变量或者是alter session完成,如果会话没有特殊的设置,将与nls_instance_parameters一致。

1、字符集由AL32UTF8修改为ZHS16GBK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
13:51:26 SYS@ boston> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------------------------------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.4.0

提示要修改的新的字符集必须大于旧的字符集才可以

1
2
3
4
5
13:51:36 SYS@ boston> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set

跳过超集的检查

1
2
3
4
5
6
7
8
13:59:34 SYS@ boston> alter system enable restricted session; 
System altered.
Elapsed: 00:00:02.05
13:59:48 SYS@ boston> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
ALTER DATABASE character set INTERNAL_USE ZHS16GBK
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active

查看当前活动的会话

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
14:02:48 SYS@ boston> select sid, serial#,program ,status from v$session;

SID SERIAL# PROGRAM STATUS
---------- ---------- ------------------------------------------------------------------------------------------------ ----------------
1 1 oracle@dax-mysql-slave (VKTM) ACTIVE
2 1 oracle@dax-mysql-slave (DIA0) ACTIVE
3 1 oracle@dax-mysql-slave (CKPT) ACTIVE
4 3 oracle@dax-mysql-slave (MMNL) ACTIVE
6 11 oracle@dax-mysql-slave (SMCO) ACTIVE
101 1 oracle@dax-mysql-slave (GEN0) ACTIVE
102 1 oracle@dax-mysql-slave (MMAN) ACTIVE
103 1 oracle@dax-mysql-slave (SMON) ACTIVE
105 1603 sqlplus@dax-mysql-slave (TNS V1-V3) ACTIVE
201 1 oracle@dax-mysql-slave (PMON) ACTIVE
202 1 oracle@dax-mysql-slave (DIAG) ACTIVE
203 1 oracle@dax-mysql-slave (DBW0) ACTIVE
204 1 oracle@dax-mysql-slave (RECO) ACTIVE
207 145 sqlplus@dax-mysql-slave (TNS V1-V3) INACTIVE
301 291 oracle@dax-mysql-slave (W000) ACTIVE
302 1 oracle@dax-mysql-slave (PSP0) ACTIVE
303 1 oracle@dax-mysql-slave (DBRM) ACTIVE
304 1 oracle@dax-mysql-slave (LGWR) ACTIVE
305 3 oracle@dax-mysql-slave (MMON) ACTIVE
306 199 sqlplus@dax-mysql-slave (TNS V1-V3) INACTIVE

查看当前会话的sid

1
2
3
4
14:02:56 SYS@ boston> select userenv('sid') from dual;
USERENV('SID')
--------------
105

尝试杀掉sqlplus连接进来的两个inactive的会话

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
14:06:46 SYS@ boston> alter system kill session '207,145';
System altered.
Elapsed: 00:00:00.00
14:07:11 SYS@ boston> alter system kill session '306,199';
System altered.

14:07:27 SYS@ boston> select sid, serial#,program ,status from v$session;

SID SERIAL# PROGRAM STATUS
---------- ---------- ------------------------------------------------------------------------------------------------ ----------------
1 1 oracle@dax-mysql-slave (VKTM) ACTIVE
2 1 oracle@dax-mysql-slave (DIA0) ACTIVE
3 1 oracle@dax-mysql-slave (CKPT) ACTIVE
4 3 oracle@dax-mysql-slave (MMNL) ACTIVE
6 11 oracle@dax-mysql-slave (SMCO) ACTIVE
101 1 oracle@dax-mysql-slave (GEN0) ACTIVE
102 1 oracle@dax-mysql-slave (MMAN) ACTIVE
103 1 oracle@dax-mysql-slave (SMON) ACTIVE
105 1603 sqlplus@dax-mysql-slave (TNS V1-V3) ACTIVE
201 1 oracle@dax-mysql-slave (PMON) ACTIVE
202 1 oracle@dax-mysql-slave (DIAG) ACTIVE
203 1 oracle@dax-mysql-slave (DBW0) ACTIVE
204 1 oracle@dax-mysql-slave (RECO) ACTIVE
207 145 sqlplus@dax-mysql-slave (TNS V1-V3) KILLED
302 1 oracle@dax-mysql-slave (PSP0) ACTIVE
303 1 oracle@dax-mysql-slave (DBRM) ACTIVE
304 1 oracle@dax-mysql-slave (LGWR) ACTIVE
305 3 oracle@dax-mysql-slave (MMON) ACTIVE
306 199 sqlplus@dax-mysql-slave (TNS V1-V3) KILLED

再次执行仍然提示有活动会话

1
2
3
4
5
14:07:29 SYS@ boston>  ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
ALTER DATABASE character set INTERNAL_USE ZHS16GBK
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active

重启数据库再次修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
14:10:54 SYS@ boston> shutdown immeidate
SP2-0717: illegal SHUTDOWN option
14:11:02 SYS@ boston> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
14:11:16 SYS@ boston> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 503319712 bytes
Database Buffers 1090519040 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.
14:11:46 SYS@ boston> select sid, serial#,program ,status from v$session;
SID SERIAL# PROGRAM STATUS
---------- ---------- ------------------------------------------------------------------------------------------------ ----------------
1 1 oracle@dax-mysql-slave (VKTM) ACTIVE
2 1 oracle@dax-mysql-slave (DIA0) ACTIVE
3 1 oracle@dax-mysql-slave (CKPT) ACTIVE
4 1 oracle@dax-mysql-slave (MMNL) ACTIVE
101 1 oracle@dax-mysql-slave (GEN0) ACTIVE
102 1 oracle@dax-mysql-slave (MMAN) ACTIVE
103 1 oracle@dax-mysql-slave (SMON) ACTIVE
201 1 oracle@dax-mysql-slave (PMON) ACTIVE
202 1 oracle@dax-mysql-slave (DIAG) ACTIVE
203 1 oracle@dax-mysql-slave (DBW0) ACTIVE
204 1 oracle@dax-mysql-slave (RECO) ACTIVE
301 5 sqlplus@dax-mysql-slave (TNS V1-V3) ACTIVE
302 1 oracle@dax-mysql-slave (PSP0) ACTIVE
303 1 oracle@dax-mysql-slave (DBRM) ACTIVE
304 1 oracle@dax-mysql-slave (LGWR) ACTIVE
305 1 oracle@dax-mysql-slave (MMON) ACTIVE
16 rows selected.

Elapsed: 00:00:00.03
14:11:47 SYS@ boston> alter system enable restricted session;
System altered.
Elapsed: 00:00:02.04
14:12:00 SYS@ boston> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.

修改完成再次重启数据库,(修改完字符集之后关闭数据库会花费很长时间)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
14:12:13 SYS@ boston> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
14:18:21 SYS@ boston> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 503319712 bytes
Database Buffers 1090519040 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.

查看字符集

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
14:19:40 SYS@ boston> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET ZHS16GBK
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.4.0
20 rows selected.

字符集修改完成,数据库的字符集更改会出现乱码,操作要慎重。

2、数据库字符集由ZHS16GBK改为AL32UTF8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
15:01:20 SYS@ boston> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET ZHS16GBK
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.4.0
20 rows selected.
15:05:51 SYS@ boston> alter system enable restricted session;
System altered.
Elapsed: 00:00:02.06
15:07:05 SYS@ boston> ALTER DATABASE character set AL32UTF8;
ALTER DATABASE character set AL32UTF8
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
Elapsed: 00:00:00.00

这个报错证明AL32UTF8字符集并不是ZHS16GBK超集。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
15:07:12 SYS@ boston> ALTER DATABASE character set INTERNAL_USE AL32UTF8; 
ALTER DATABASE character set INTERNAL_USE AL32UTF8
*
ERROR at line 1:
ORA-12721: operation cannot execute when other sessions are active

Elapsed: 00:00:00.01
15:07:23 SYS@ boston> select sid, serial#,program ,status from v$session;

SID SERIAL# PROGRAM STATUS
---------- ---------- ------------------------------------------------ --------
1 1 oracle@dax-mysql-slave (VKTM) ACTIVE
2 1 oracle@dax-mysql-slave (DIA0) ACTIVE
3 1 oracle@dax-mysql-slave (CKPT) ACTIVE
4 3 oracle@dax-mysql-slave (MMNL) ACTIVE
7 5 oracle@dax-mysql-slave (SMCO) ACTIVE
101 1 oracle@dax-mysql-slave (GEN0) ACTIVE
102 1 oracle@dax-mysql-slave (MMAN) ACTIVE
103 1 oracle@dax-mysql-slave (SMON) ACTIVE
104 27 oracle@dax-mysql-slave (W000) ACTIVE
201 1 oracle@dax-mysql-slave (PMON) ACTIVE
202 1 oracle@dax-mysql-slave (DIAG) ACTIVE
203 1 oracle@dax-mysql-slave (DBW0) ACTIVE
204 1 oracle@dax-mysql-slave (RECO) ACTIVE
205 15 sqlplus@dax-mysql-slave (TNS V1-V3) INACTIVE
301 15 sqlplus@dax-mysql-slave (TNS V1-V3) INACTIVE
302 1 oracle@dax-mysql-slave (PSP0) ACTIVE
303 1 oracle@dax-mysql-slave (DBRM) ACTIVE
304 1 oracle@dax-mysql-slave (LGWR) ACTIVE
305 3 oracle@dax-mysql-slave (MMON) ACTIVE
306 139 sqlplus@dax-mysql-slave (TNS V1-V3) ACTIVE

20 rows selected.
Elapsed: 00:00:00.01
15:07:36 SYS@ boston> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
15:07:55 SYS@ boston> startup
ORACLE instance started.

Total System Global Area 1603411968 bytes
Fixed Size 2253664 bytes
Variable Size 503319712 bytes
Database Buffers 1090519040 bytes
Redo Buffers 7319552 bytes
Database mounted.
Database opened.
15:08:38 SYS@ boston>
15:13:24 SYS@ boston> select * from nls_database_parameters;

PARAMETER VALUE
------------------------------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET AL32UTF8
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.4.0

字符集修改完成

点击阅读

[Linux] linux操作系统字符集与ssh工具字符集配置问题


1、操作系统字符集设置

centos6和7的字符集文件位置不同

1
2
CentOS6.x 字符集配置文件在/etc/syscconfig/i18n
CentOS7.x 字符集配置文件在/etc/locale.conf

以centos7为例,修改字符集
cat /etc/locale.conf

1
LANG="zh_CN.UTF-8"

修改为GBK字符集
cat /etc/locale.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
LANG="zh_CN.GBK"
[root@dax-mysql-slave ~]# locale
LANG=zh_CN.GBK
LC_CTYPE="zh_CN.GBK"
LC_NUMERIC="zh_CN.GBK"
LC_TIME="zh_CN.GBK"
LC_COLLATE="zh_CN.GBK"
LC_MONETARY="zh_CN.GBK"
LC_MESSAGES="zh_CN.GBK"
LC_PAPER="zh_CN.GBK"
LC_NAME="zh_CN.GBK"
LC_ADDRESS="zh_CN.GBK"
LC_TELEPHONE="zh_CN.GBK"
LC_MEASUREMENT="zh_CN.GBK"
LC_IDENTIFICATION="zh_CN.GBK"
LC_ALL=

2、系统字符集为utf-8,securecrt工具的字符集为gb2312,oracle字符集为ZHS16GBK



如果使用securtcrt工具,设置该工具字符集为gb2312(小于gbk字符集)

进入操作系统如果操作系统有中文字符,会出现乱码的情况

分别查看以utf8编码的文件和ansi编码的文件

以gb2312字符集连接进来的securecrt工具,查看ansi编码的文件正常,查看utf8编码的文件乱码。
使用securecrt工具查看数据库中存在中文的数据:

3、系统字符集为utf-8,securecrt工具的字符集为urf-8,oracle字符集为ZH16GBK




进入操作系统如果操作系统有中文字符,显示正常:

分别查看以utf8编码的文件和ansi编码的文件

以utf-8字符集连接进来的securecrt工具,查看ansi编码的文件乱码,查看utf8编码的文件正常。
使用securecrt工具查看数据库中存在中文的数据:

查看带有中文的数据全部显示乱码

4、结论:

使用ssh工具连接到服务器是要注意连接工具的字符集,如果只在系统级别操作,要注意保持工具字符集和操作系统字符集的一致性。如果要查询数据库里面带有中文的相关数据,要注意保持工具字符集和操作系统字符集的一致性,否则查询结果会出现乱码。

点击阅读

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog