Posts

Showing posts with the label database

Digital Marketing

Watch out for LEFT JOIN with additional conditions in SQL

SELECT  * FROM    a LEFT JOIN b ON      b.a_id = a.id WHERE   b.column = 'sth' Return the same result as (but less efficient) SELECT  * FROM    a INNER JOIN b ON      b.a_id = a.id WHERE   b.column = 'sth' Put additional conditions on left table on left join will actually filter out those rows where b.column is null. Because   NULL in SQL  doesn't equal to anything. So the only exception to put extra condition on left table of left join is to check b.column is null or not. If you actually want to return those  b.column = 'sth' and at the same time with all records of table a, then the condition should be moved into ON clause: SELECT  * FROM    a LEFT JOIN         b ON      b.a_id = a.id AND b.column = 'sth'

Watch out for LEFT JOIN with additional conditions in SQL

SELECT  * FROM    a LEFT JOIN b ON      b.a_id = a.id WHERE   b.column = 'sth' Return the same result as (but less efficient) SELECT  * FROM    a INNER JOIN b ON      b.a_id = a.id WHERE   b.column = 'sth' Put additional conditions on left table on left join will actually filter out those rows where b.column is null. Because   NULL in SQL  doesn't equal to anything. So the only exception to put extra condition on left table of left join is to check b.column is null or not. If you actually want to return those  b.column = 'sth' and at the same time with all records of table a, then the condition should be moved into ON clause: SELECT  * FROM    a LEFT JOIN         b ON      b.a_id = a.id AND b.column = 'sth'

How to connect to remote MySQL server by SSH tunnel

Run: ssh - L 3306 : 127.0 . 0.1 : 3306 database@ goyun.info -L [bind_address:]port:host:hostport              Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. Then you can access MySQL server remotely: mysql - h 127.0 . 0.1

Example To Update / Ping a JDBC Connection Pool in Oracle GlassFish / Payara Server

asadmin list-jdbc-connection-pools goyun.info _pool asadmin ping-connection-pool  goyun.info _pool Command ping-connection-pool executed successfully. asadmin get resources.jdbc-connection-pool.goyun.info_pool.property asadmin get resources.jdbc-connection-pool.goyun.info_pool.property.ServerName asadmin set resources.jdbc-connection-pool.i88_ca_pool.property.ServerName=it.goyun.info resources.jdbc-connection-pool.google_mysql.property.ServerName=goyun.info_pool Command set executed successfully. (Optional) If needed, restart the server. Some parameters require server restart. Changing ServerName, User, Password does not need to restart the server. asadmin ping-connection-pool goyun.info_pool Command ping-connection-pool executed successfully.

A simple python script to keep an eye on mysql process

The following codes are the same, they are just shown on different formats. Choose the one you like. ''' @author: it.goyun.info ''' import MySQLdb import time db = MySQLdb.connect(host= "192.168.1.19" , user= "i88ca" , passwd= " goyun.info " , db= " goyun.info " ) #create a cursor for the select cur = db.cursor() while ( True ): cur.execute( "show processlist;" ) for row in cur.fetchall() : # print row[0], row[1] print row[ 7 ] time.sleep( 8 ); # close the cursor cur.close() # close the connection db.close ()

MongoDB show databases

Connect to the MongoDB shell and then execute show dbs command to list all the currently available database on MongoDB server. > show dbs

Connect with data services by Java

Azure Cosmos DB   is a globally distributed database service that allows developers to work with data using a variety of standard APIs, such as SQL, MongoDB, Cassandra, Graph, and Table. The  Spring Boot Starter  makes it easy to store data in and retrieve data from your Azure Cosmos DB with SQL API.

Google Cloud Bigtable HBase client works with Hadoop and is interface compatible with Apache HBase

Image
Unlike DynamoDB and DocumentDB, which expose proprietary APIs, Google Cloud Bigtable is standardized on the HBase API. This feature instantly makes it compatible with the Hadoop tools and its thriving ecosystem. The API enables bulk ingestion and export using standard HBase tools. Developers can use HBase Java client for integration with common Hadoop open source tools. With single-digit millisecond reads/writes, Google claims that its NoSQL database is 3X faster than HBase, Cassandra, and DynamoDB. Customers can self-provision a Bigtable cluster with a minimum of 3 nodes. Each node will deliver up to 10,000 queries per second and 10 MB/s of throughput. The cluster can be based on SSD storage backends. The service costs $0.65 / hour per node with $0.17 per GB per month of SSD storage. With the addition of this service to its database portfolio, Google hopes to attract enterprise workloads from the finance, IoT, and retail verticals. Similar to Yodlee, Bigtable can be used for storing a...

Fixed mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when executing 'SELECT INTO OUTFILE'

To solve the problem: mysqldump: Got error: 1290: The MySQL server is running with the --secure-file-priv option so it cannot  execute this statement when executing 'SELECT INTO OUTFILE' you can run SHOW VARIABLES LIKE "secure_file_priv"; and use the folder you are told there as the output folder in your mysqldump command. Example: mysql> SHOW VARIABLES LIKE "secure_file_priv"\G; *************************** 1. row *************************** Variable_name: secure_file_priv         Value: /var/lib/mysql-files/ 1 row in set (0.00 sec)

NoSQL systems' main advantages and obstacles

Advantages: Elastic scaling:  NoSQL systems are designed with the ability to expand transparently in order to take advantage of the addition of any new nodes. Less administration Better economics:  use clusters of inexpensive commodity servers. Flexible data models Obstacles: Programming models:  few facilities for ad-hoc query and analysis. Transaction support Maturity Support Expertise : fewer experts. LIST OF NOSQL DATABASES

Operator Difference: "MEMBER OF" vs "IN" in JPA

JPA distinguishes between the MEMBER OF operator, which should be used for checking a collection field , and the IN operator, which should be used for checking other collections, such as a collection that is passed to the query as a parameter. For example: 'fido' MEMBER OF person.dogs 'fido' IN :dogs

Reads from Amazon DocumentDB replicas are eventually consistent.

 Reads from Amazon DocumentDB replicas return the data in the same order as it was written on the primary, and there is often less than a 50 ms replication lag. You can monitor the replica lag for your cluster using the Amazon CloudWatch metrics DBInstanceReplicaLag and DBClusterReplicaLagMaximum. 

Database Lifecycle

The life-cycle of a database instance includes creating, modifying, maintaining and upgrading, performing backups and restores, rebooting, and deleting the instance.

How to install mysql-workbench on CentOS or RHEL or Oracle Linux 7 or Fedora

Download path----- http://dev.mysql.com/downloads/ MySQL Yum Repository $ sudo yum install MySQL-Yum -Link.rpm such as: $ sudo yum install mysql-workbench-commercial (or community) $ sudo yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm Start it using this command: $ mysql-workbench &

How to fix: TypeError: not all arguments converted during string formatting in Python MySQLdb

If you encounter something similar to the following: Traceback (most recent call last):   File "scotia.failed.email.py", line 13, in <module>     cursor.execute (' select * from fail f where f.emailid= (%s) ', (emailid))   File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 187, in execute     query = query % tuple([db.literal(item) for item in args]) TypeError: not all arguments converted during string formatting: # Instead of: cursor . execute ( ' select * from fail f where f.emailid= (%s) ' , (emailid)) # Use: cursor . execute ( ' select * from fail f where f.emailid= (%s) ' , [emailid]) # Another example: count = cursor . execute ( ' select * from fail f join contacts c on f.contactid=c.contactid where f.emailid= (%s) and c.email = (%s) ' , [emailid,email]) print count

Comparison of pricing: Google Cloud SQL vs AWS RDS

A direct comparison of pricing shows that AWS RDS is cheaper than corresponding Google Cloud SQL pay-per-hour options, but other costs such as data storage and transfer fees, etc needs to be considered. Google Cloud SQL supports instances up to 500GB in size while Amazon RDS goes up to 3TB. Google's MySQL database is also general available, offering more storage and SLA-backed uptime. Amazon RDS comes as a first choice, with competitive pricing and a whole range of features. You can easily build a high availability database yourself, with automated replication and lots of monitoring options. Google Cloud SQL provides an impressive offering, but can be a bit harder to set up. It helps if you are already familiar with the Google Cloud. They used the experience gained from running Google search to build their infrastructure, so it’s proven and fast. But you do pay the price for it.

Datasets

Google Tables helps you search thousands of public Fusion Tables, or millions of public tables from around the web you can import to Fusion Tables . Google Public Data http://www.freebase.com Social Network Analysis Interactive Dataset Library (Social Network Datasets) Datasets for Data Mining http://usgovxml.com http://aws.amazon.com/datasets http://databib.org http://datacite.org http://figshare.com http://linkeddata.org http://reddit.com/r/datasets http://thedatahub.org alias http://ckan.net http://quandl.com http://archive.ics.uci.edu/ml/ http://crawdad.org/ http://data.austintexas.gov http://data.cityofchicago.org http://data.govloop.com http://data.gov.uk/ http://data.medicare.gov http://data.seattle.gov http://data.sfgov.org http://data.sunlightlabs.com https://datamarket.azure.com/ http://developer.yahoo.com/geo/g... http://econ.worldbank.org/datasets http://en.wikipedia.org/wiki/Wik... http://factfinder.census.gov/ser... http://ftp.ncbi.nih.gov/ http://gettingpastgo.socrat...

Difference between Google Cloud BigTable and Datastore

The main differences are: BigTable seems to be designed for HBase compatibility, whereas Datastore is more geared towards Python/Java/Go web app developers (originally App Engine)  BigTable is 'a bit more IaaS' than Datastore in that it's not 'just there' but requires a cluster to be  configured . BigTable supports only one index - the 'row key' (the entity key in Datastore) This means queries are on the Key, unlike Datastore's indexed properties BigTable supports atomicity only on a single row - there are no transactions Mutations and deletions appear not to be atomic in BigTable, whereas Datastore provides eventual and strong consistency, depending on the read/query method The billing model is very different: Datastore charges for read/write operations, storage and bandwidth BigTable  charges  for  'nodes' , storage and bandwidth

How to partially rollback your database transaction: example of The SAVEPOINT Command in SQL

A SAVEPOINT is a point in a transaction when you can roll the transaction back to a certain point without rolling back the entire transaction. SQL > SAVEPOINT SP1; Savepoint created. SQL > DELETE FROM CUSTOMERS WHERE ID = 1 ; 1 row deleted. SQL > SAVEPOINT SP2; Savepoint created. SQL > DELETE FROM CUSTOMERS WHERE ID = 2 ; 1 row deleted. SQL > SAVEPOINT SP3; Savepoint created. SQL > DELETE FROM CUSTOMERS WHERE ID = 3 ; 1 row deleted. Now that the three deletions have taken place, say you have changed your mind and decided to ROLLBACK to the SAVEPOINT that you identified as SP2. Because SP2 was created after the first deletion, the last two deletions are undone: SQL > ROLLBACK TO SP2; Rollback complete. Notice that only the first deletion took place since you rolled back to SP2.

What is the consistency model of Amazon DynamoDB?

When reading data from Amazon DynamoDB, users can specify whether they want the read to be eventually consistent or strongly consistent: Eventually Consistent Reads (Default) – the eventual consistency option maximizes your read throughput. However, an eventually consistent read might not reflect the results of a recently completed write. Consistency across all copies of data is usually reached within a second . Repeating a read after a short time should return the updated data. Strongly Consistent Reads — in addition to eventual consistency, Amazon DynamoDB also gives you the flexibility and control to request a strongly consistent read if your application, or an element of your application, requires it. A strongly consistent read returns a result that reflects all writes that received a successful response prior to the read.