Tuesday, 11 March 2014

The listener supports no services

This morning I try to connect oracle server from client Oracle SQL Developer, throw me an error :
ORA-12505 error:TNS listener does not currently know of SID given in connection
Check the lsnrctl status on server side


[root@localhost admin]# lsnrctl
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 12-MAR-2014 10:31:59
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production
Start Date                12-MAR-2014 10:28:15
Uptime                    0 days 0 hr. 3 min. 45 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.155)(PORT=1521)))
The listener supports no services
The command completed successfully
LSNRCTL>


Try to register the local listener


[root@localhost admin]# sqlplus sys/***** as sysdba
SQL*Plus: Release 12.1.0.1.0 Production on Wed Mar 12 10:32:48 2014
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


SQL>alter system set local_listener='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.155)(PORT=1521)))';

System altered.


restart the listener and check status again, service started
[root@localhost admin]# lsnrctl status
LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 12-MAR-2014 11:31:04
Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production
Start Date                12-MAR-2014 10:33:56
Uptime                    0 days 0 hr. 57 min. 7 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.155)(PORT=1521)))
Services Summary...
Service "orcl.localdomain" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB.localdomain" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "pdborcl.localdomain" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully


try to connect from Oracle SQL Developer tools , it's work fine.
---------------------------------------------------------------------------------









Wednesday, 5 March 2014

ORA-65096: invalid common user or role name

SQL> create user garey identified by 123123;
create user garey identified by 123123
            *
ERROR at line 1:
ORA-65096: invalid common user or role name

SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> select pdb from v$services;
PDB
------------------------------
PDBORCL
CDB$ROOT
CDB$ROOT
CDB$ROOT
CDB$ROOT
SQL>


we need to decide whether create common user or a local user,
to create a common  user , the name must start with c##


SQL> create user c##garey identified by 123123;
User created.
SQL>


to create a user in orcl
SQL> alter session set container=PDBORCL;
Session altered.
SQL> create user garey identified by 123123;
User created.
SQL>

Wednesday, 22 January 2014

Export MySQL query results in csv format

select *
from table
where .....
INTO OUTFILE '/tmp/output.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

Tuesday, 10 December 2013

mysqlbinlog: unknown variable 'default-character-set=utf8'

Today when I try to check the log-bin file, encounter an error:
mysqlbinlog: unknown variable 'default-character-set=utf8'
it's because inside the my.cnf  got
default-character-set=utf8


the default-character-set is deprecated in 5.5. we should use instead:
character-set-server = utf8
 
or add ----no-defaults
 
mysqlbinlog --no-defaults -v logbin-log.000003 > logbin003.sql
 
-----------------------The End----------------------------

Wednesday, 13 November 2013

MySQL 5.6 GTID replication "doesn't exists on query" error fix


Master-slave environment encounter error 1858, it's happening when drop an object on master, but the object doesn't on slave , this is the error:
 Last_SQL_Error: Error 'Can't drop database 'dba1'; database doesn't exist' on query. Default database: 'dba1'. Query: 'drop database dba1'
firstly I try to skip this error:
mysql> set global sql_slave_skip_counter=1;
ERROR 1858 (HY000): sql_slave_skip_counter can not be set when the server is running with @@GLOBAL.GTID_MODE = ON. Instead, for each transaction that you want to skip, generate an empty transaction with the same GTID as the transaction

Oops, GTID can't use sql_slave_skip_counter any more, try to generate a null transaction to skip the error, check the binlog file and get the last gtid
mysql> show binary logs;
+----------------+-----------+
| Log_name       | File_size |
+----------------+-----------+
| log-bin.000020 |       196 |
| log-bin.000021 |      1119 |
+----------------+-----------+
2 rows in set (0.00 sec)
mysql> exit
Bye
[dbaroot@dba ~]$ su -
Password:
[root@dba ~]# mysqlbinlog /usr/local/mysql/data/log-bin.000021





Run next on slave MySql
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> set session gtid_next='6433e872-0fad-11e3-a916-00155d01c300:24';
Query OK, 0 rows affected (0.00 sec)
mysql> begin;commit;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> set session gtid_next=AUTOMATIC;
Query OK, 0 rows affected (0.00 sec)
mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)
Show slave status\G again, that error transaction skip already, master-slave working fine.
-------------------------------the end-------------------------------------------

Wednesday, 6 November 2013

Installing EPEL repository on Centos 6

[root@dba local]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
--2013-11-07 13:17:22--  http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Resolving dl.fedoraproject.org... 209.132.181.26, 209.132.181.27, 209.132.181.23, ...
Connecting to dl.fedoraproject.org|209.132.181.26|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14540 (14K) [application/x-rpm]
Saving to: “epel-release-6-8.noarch.rpmâ€

100%[=======================================================================================================================================>] 14,540      --.-K/s   in 0.002s
2013-11-07 13:17:22 (5.76 MB/s) - “epel-release-6-8.noarch.rpmâ€
[root@dba local]# ls -la
total 297256
drwxr-xr-x. 13 root  root       4096 Nov  7 13:17 .
drwxr-xr-x. 13 root  root       4096 Nov  5 07:53 ..
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 bin
-rw-r--r--.  1 root  root      14540 Nov  5  2012 epel-release-6-8.noarch.rpm
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 etc
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 games
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 include
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 lib
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 lib64
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 libexec
drwxr-xr-x. 13 mysql mysql      4096 Nov  7 11:39 mysql
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 sbin
drwxr-xr-x.  5 root  root       4096 Nov  5 07:53 share
drwxr-xr-x.  2 root  root       4096 Sep 23  2011 src
[root@dba local]# rpm -Uvh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]
[root@dba local]# ls -lah /etc/yum.repos.d/ | grep epel
-rw-r--r--.  1 root root  957 Nov  5  2012 epel.repo
-rw-r--r--.  1 root root 1.1K Nov  5  2012 epel-testing.repo

------------------The end-------------------------------------------------------------------

Friday, 25 October 2013

MySQL export table to csv file

SELECT id, table_id, indices,create_time
INTO OUTFILE '/usr/local/mysql/tblTest.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM tblTest WHERE 1;