MySQL: Unable to connect to database ‘xxx’ on server ‘xxx’ on port xx with user ‘root’

Quick tip:

# Problem:

MySQL: Unable to connect to database 'xxx' on server 'xxx' on port xx with user 'root' - Access denied for user 'root'@'xxxxx'

 

Solution:

GRANT ALL PRIVILEGES ON *.* TO root@'xxxxx' IDENTIFIED BY '$PASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;

 

Have a nice week!
Matheus.

Transporting 12TB Database Over 4.000 km with EMC DDomain

Hi all!
I’m here to share this is great whitepaper by EMC about Transporting a 12 TB Oracle Database almost 4.000km using Data Domain to Backup and restore.

DDTransportation
Take a look:
https://www.emc.com/collateral/software/white-papers/h8238-oracle-remote-recovery-datadomain-wp.pdf

It’s nice to see how deduplication was a key-factor to the success of project.
It’s really a good feature that provides lots of optimization to backup/recover databases, besides diskspace saving, backup window reducing, network interface load reducing, etc.

Have a nice weekend!

Monitoring MySQL with Nagios – Quick View

Hi all!
As you know, we have some commercial solutions to monitoring/alerting MySQL, like MySQL Enterprise Monitor or Oracle Grid/Cloud Control.

But, regarding we are using MySQL instead of Oracle Database, we can assume it’s probably a decision taken based on cost. So, considering Open Source solutions, we basically have Nagios, Zabbix, OpenNMS…

MangagedMonitoringConsole

 

Thinking on Nagios, in my opinion the “supra sumo” is mysql_health_check.pl.
Below whitepaper and presentation:
White Paper
Presentation
Code
Good one by Sheeri Cabral and posted here!

Any way, with theese two we can make lots of magic:

1. check_mysql.pl
– Check status of MySql server (slow queries, etc)
– Queries per second graph

2. check_db_query.pl
– Allowes to run SQL Queries and setting thresholds for warning e critical. Ex:

check_db_query.pl -d database -q query [-w warn] [-c crit] [-C conn_file] [-p placeholder]

Ex for Nagios call:

define command{
command_name    check_db_entries
command_line    /usr/local/bin/perl $USER1$/check_db_query.pl -d "$ARG1$" -q "$ARG2$" $ARG3$
}

So, now it’s just make your queries and implement your free monitoring on MySQL! 🙂
Matheus.

Alter (Fix) Oracle Database Date

When you haven’t access to SO and just have to alter database date…

# Fix Date:

ALTER SYSTEM SET fixed_date = '2016-04-05-12:00:00';

# Unfix Date:

ALTER SYSTEM SET fixed_date = NONE;

 

OBS: Just to make it clear: The date will be really “fixed”. The time will “stop”. Seconds, minutes will not advance…
Matheus.

Export/Backup directly to Zip using MKNOD!

We all faced that situation when we have to make a logical backup/export and haven’t so much area to do that, right?
We know the export usually compress a lot on zip/gzip… It wouldn’t be great if we can export directly to compressed file?

zip
This situation become much more common because of Datapump, that requires a directory accessible by database server. If you have not possibility to make a mounting point or any other area, this can help…

## BKP with MKNOD
BKP_DEST=/just/example
DATE=`date +%Y%m%d%H%M`
cd $BKP_DEST
mknod bkp_$DATE.dmp p
gzip  bkp_$DATE.dmp.gz &
### Uncomment and Ajust one of:
## MySQL:
#mysqldump -u $user -p$password $database > bkp_$DATE.dmp
## Oracle (Datapump or EXP)
expdp \"/ as sysdba\" dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log compress=y
#expdp $user/$password dumpfile=bkp_$DATE.dmp full=y directory=DIRECTORY_EXAMPLE logfile=log_bkpzipped.log
#exp \"/ as sysdba\" file=bkp_$DATE.dmp log=log_bkpzipped.log compress=y [tables=owner.table,..] [owner=schema1,..] [...]

Hugs!
Matheus.

Tip for the Future: Segmentation fault because of LD_LIBRARY_PATH

More than once I forgot to set LD_LIBRARY_PATH in new environments and sometimes I faced awkward errors. The most common is “Segmentation Fault”.
Today a lost almost 15 minutes searching about Segmentation Fault related to Datapump on 11.2, then I realized I forgot the LD_LIBRARY_PATH again…

Other day, in a Upgrade from 11.2.0.3.6 to 11.2.0.4.2 I get stuck in lots of errors on upgrade process. Bullshit again, after a few minutes of errors and searching I founded a post, somewhere, talking about the variables setting.

So, Matheus from the Future: Check if LB_LIBRARY_PATH and other variables are setted for the right Oracle Home.

I expect this post save me from this same pain in the future. 😛
Thanks.

Matheus.

Optimize fragmented tables in MySQL

It happens on MySQL, as you know. Run an Optimize Table solve the question.
BUT, be careful! During the optimize the table stay locked (writing is not possible).

Fragmentation-table
(Fragmented Table)

So what?
To not cause a lock in every table, the script below shows and runs (if you want to list but not run, comment the line) only for tables that have fragmentation.

It was very useful to me! 🙂

#!/bin/sh
echo -n "MySQL username: " ; read username
echo -n "MySQL password: " ; stty -echo ; read password ; stty echo ; echo
mysql -u $username -p"$password" -NBe "SHOW DATABASES;" | grep -v 'lost+found' | while read database ; do
mysql -u $username -p"$password" -NBe "SHOW TABLE STATUS;" $database | while read name engine version rowformat rows avgrowlength datalength maxdatalength indexlength datafree autoincrement createtime updatetime checktime collation checksum createoptions comment ; do
if [ "$datafree" -gt 0 ] ; then
fragmentation=$(($datafree * 100 / $datalength))
echo "$database.$name is $fragmentation% fragmented."
mysql -u "$username" -p"$password" -NBe "OPTIMIZE TABLE $name;" "$database"
fi
done
done

The resul will be like:

MySQL username: root
MySQL password:
...
mysql.db is 12% fragmented.
mysql.db optimize status OK
mysql.user is 9% fragmented.
mysql.db optimize status OK
...

This script is a full copy from this post by Robert de Bock.
Thanks, Robert!

Matheus.

Explain ORA-XXX on SQL*Plus

For those when the error is unkown/rare, SQL*Plus helps us. It’s just call “oerr” from OS.

See the Linux example (made on RHEL):

SQL>  !oerr ora 01652
01652, 00000, "unable to extend temp segment by %s in tablespace %s"
// *Cause:  Failed to allocate an extent of the required number of blocks for
//          a temporary segment in the tablespace indicated.
// *Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more
//          files to the tablespace indicated.

Pretty cool, han?

Have a nice week!
Matheus.

PRCR-1079 CRS-2674 CRS-5017 ORA-27102: out of memory Linux-x86_64 Error: 28: No space left on device

# Problem

myserver:/home/oracle>srvctl start database -d mydb
PRCR-1079 : Failed to start resource ora.mydb.db
CRS-5017: The resource action "ora.mydb.db start" encountered the following error:
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
. For details refer to "(:CLSN00107:)" in "/grid/product/11.2.0/log/myserver/agent/crsd/oraagent_oracle/oraagent_oracle.log".
CRS-2674: Start of 'ora.mydb.db' on 'myserver' failed
CRS-5017: The resource action "ora.mydb.db start" encountered the following error:
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device
. For details refer to "(:CLSN00107:)" in "/grid/product/11.2.0/log/myserver2/agent/crsd/oraagent_oracle/oraagent_oracle.log".
CRS-2674: Start of 'ora.mydb.db' on 'myserver2' failed
CRS-2632: There are no more servers to try to place resource 'ora.mydb.db' on that would satisfy its placement policy
myserver:/home/oracle>

# Solution

On /etc/sysctl.conf ajust as below and then reload sysctl (“sysctl -p” as root):

#Old
#kernel.shmall = 24641536
#New
kernel.shmall = 4294967296

Matheus.

ORA-01994: GRANT failed: password file missing or disabled

Quick tip:

[oracle@server ~]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=$password entries=$num_users force=y

 

KB: http://docs.oracle.com/cd/B28359_01/server.111/b28310/dba007.htm#ADMIN12478

# OBS 1
“If you are running multiple instances of Oracle Database using Oracle Real Application Clusters, the environment variable for each instance should point to the same password file.”

# OBS 2
REMOTE_LOGIN_PASSWORDFILE need to be in EXCLUSIVE to alter user with sysdba.

# OBS 3
Users can be chacked on V$PWFILE_USERS.

# OBS 4
Entries represent the quantity of users on orapwd/with sysdba.

Matheus.