MariaDB replication some times does not working - perl

I have a problem that I have never seen before with Mysql replication (Master/Slave):
It works excellent when I execute on my PHP scripts, on the mysql console queries like "INSERT INTO". They are perfectly replicated on the mysql slave machine.
But: Not if I do this same operations on a Perl script, using Perl DBI. Then its only stored on the Mysql master server. In the mysql.log file on the slave server, nothing arrives. I have this problem since I migrated on the two servers from Mysql to MariaDB.
Is there something that a Perl DBI client should absolutely do that replicating would work?
I'm using this simple code to INSERT data:
#!/usr/bin/perl
use DBI;
$dsn = 'dbi:mysql:database=mysql;host=myhostname';
$dbh = DBI->connect($dsn, 'mouser', 'password',
{ RaiseError => 1, AutoCommit => 0 }) || exit(1);
...
$sth = $dbh->prepare("INSERT INTO mydatabase.mytable (user, domain) VALUES('$account_name', '$domain')");
$sth->execute();
$dbh->commit();
Is it possible that it does not replicate because DBI should use a mariadb driver? Like $dsn = 'dbi:mariadb:database=mysql;host=myhostname'; if that exists?
To be clear: Data inserted with your PHP script is still being replicated after switching to MariaDB, but data inserted with your Perl script isn't.

I found the reason why the replication failed with this simple Perl script:
There is written:
$dsn = 'dbi:mysql:database=mysql;host=myhostname';
...
$sth = $dbh->prepare("INSERT INTO mydatabase.mytable (user, domain) VALUES('$account_name', '$domain')");
This is not working, because DBI connects to the database "mysql" and not "mydatabase" (see "database=mysql"). Even if the INSERT INTO inserts the row directly in the database "mydatabase", MariaDB master server ignores it for the replication. Its strange that it worked perfectly with MySQL and not for MariaDB (version 5.5.46). Maybe its a bug in MariaDB, I don't know.

Related

How to change database from MySQL to Oracle in TheSchwartz

I'd like to switch database from MySQL to Oracle in perl's TheSchwartz module which is the job queue system. I suspects following code has the key.
my $client = TheSchwartz->new(
databases => [{
dsn => 'dbi:mysql:TheSchwartz',
user => 'dbi',
pass => 'xxxxxxx',
}],
verbose => 1,
);
I changed the code.
dsn => 'dbi:mysql:TheSchwartz',
to
dsn => 'dbi:Oracle:OraDB01',
then I got the message.
#Disabling DB 9e410d44ac4b9ede28c9ef34f6c1e817 because unknown
TheSchwartz doesn't tell me any clue of Oracle's error(ex password error ,or network error ....).
My question are
1. Is it possible to use Oracle in perl's TheSchwartz?
2. For dubugging ,how to get the ORA- Error message in TheSchwartz?
Any help would be welcomed.
Regards,
Using TheSchwartz is almost certainly a complete red herring here. TheSchwartz is just creating a DBI connection. So once you can successfully create a DBI connection outside of TheSchwartz, you should be able to do the same insider TheSchwartz.
The way I would approach it would be in two stages:
Write a simple DBI program to connect to the Oracle database.
Copy your successful connection details to your TheSchwartz code.
The simple DBI program I'd write, only needs to be as simple as this:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:OraDB01', 'dbi', 'xxx')
or die $DBI::errstr;
That will presumably fail in the same way as your existing code, but you'll get the raw DBI connection error which should allow you to work out what the problem is.
Obviously, you might find the DBD::Oracle documentation to be useful as well.

ODBC to SAP HANA connection timeout in Perl

Since I'm programming a Perl script to monitor the SAP HANA database, I'm experiencing problems with the connection timeout. I don't know how to set the timeout. This is my connection string:
use DBI;
use DBD::ODBC;
$dbh = DBI->connect("dbi:ODBC:dsn=$dsn");
Meanwhile in another script to monitor a Sybase database it works properly:
use DBI;
dbh = DBI->connect("dbi:Sybase:server=$dbsvr;database=$dbname;".
timeout=$timeout;"."loginTimeout=$timeout", $user, $pass);
I think the problem comes with the ODBC. Which is the way to implement a timeout using ODBC connection?
I don't believe there is a way to set SQL_ATTR_LOGIN_TIMEOUT on the connection handle via DBD::ODBC. In any case, few ODBC drivers do anything with it. However, if you are on UNIX and using the unixODBC driver manager - see Setting ODBC driver environment variables automatically
You basically add "DMConnAttr = CONNECTION_ATTRIBUTE=value" to you odbc.ini file where CONNECTION_ATTRIBUTE is an ODBC connection attribute (e.g., SQL_ATTR_CONNECTION_TIMEOUT) and value is what you want to set it to.
It is commom to confused with connection and query timeout:
DMStmtAttr = SQL_ATTR_QUERY_TIMEOUT=2
DMConnAttr = SQL_ATTR_CONNECTION_TIMEOUT=2
Connection may be ok but query response take more time than normal

Perl script to connect oracle database

I am new to Perl Programming and database connectivity. Can anyone please let me know step by step procedure to write Perl Script for Oracle Database connectivity.
My Perl Verion is:
This is perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x64-multi-thread
Copyright 1987-2015, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
I have tried the below:
my $db = DBI->connect("dbi:Oracle:Local","SYSTEM","SYSTEM") or die print ("could not connect! $DBI::errstr \n");
Since I don't know what is this "dbi:Oracle:Local" I could not able to connect to Database.
Can you please let me know what is dbi, Oracle, local. if it is Hostname and oracle database name, how can I find the same in my computer.
Do I need to set any ENV variable in Perl? If so, where and what I need to set?
dbi:Oracle lets DBI know which driver to use. If you're connecting to an Oracle database, you'll never change these.
Local is either an actual database name on the local system, or a name listed in TNSNAMES.ORA. Substitute the name of the local database you'd like to connect to.
The next two parameters are username and password.
If you're connecting remotely, or need to do something more elaborate, consult the docs, or one of the many available guides.
my $db = DBI->connect("dbi:Oracle:Local","SYSTEM","SYSTEM");
"dbi" is a string,
"Oracle" is the driver type,
"local" is the database name,
First "SYSTEM" is the username and second one is password.
use DBI;
my $dbh = DBI->connect( "dbi:Oracle:databaseName", 'username', 'passwd' ) or die($DBI::errstr, "\n");
First read the basic concept of Simple Database access using Perl DBI and SQL.

Perl script to connect to Sybase database

I am writing a Perl script to connect to Sybase machine having particular database name called PPDB but it is not working.
my $dbh = DBI->connect( "dbi:Sybase:server=sybase IP address; database=PP_DB;port=5000","sa", "password" );
This is the error I'm getting
Can't connect to data source 'dbi:Sybase ASE:server=server
name;database=PP_DB;port=5000' because I can't work out what driver to
use (it doesn't seem to contain a 'dbi:driver:' prefix and the
DBI_DRIVER env var is not set) at ./update_database.pl line 6
Don't know what's wrong in this. Your suggestions are welcome.
The server parameter in the data source name expects a Sybase server name. If you want to specify an IP address then you need to use host instead:
my $dbh = DBI->connect( 'dbi:Sybase:host=<sybase IP address>;database=PP_DB;port=5000', qw/ sa password /);

Perl DBI connection to PostgreSQL doesn't die() on database error

I am used to Perl "crashing" my script when a SQL goes bad, but Postgres is just giving the error to the Apache error log and the script continues. Evil behaviour for debugging code.
Now I have asked the Oracle of Google but either I am asking the wrong questions or, very unlikely, I am the only one with that problem. ;)
In Short: I want the same fault behaviour with Postgres as MySQL does, ie, "crash" the script and take heed of use CGI::Carp qw(fatalsToBrowser); and just show me the faulty SQL statement.
I am using good old DBI to access the PG-DB, Postgres 8.4 and Perl 5.10.1 on Ubuntu 10.04 on my server, if that matters. All packages are from the official rep.
EDIT:
Thanks to Richard Huxton this is solved, leaving the solution for others to find.
our $dbh = DBI->connect($DBUrl, $DBUser, $DBPass,{ RaiseError => 1}
) || die "Could not connect to database: $DBI::errstr";
Surely you just need to set RaiseError when you make the connection?
https://metacpan.org/module/DBI