Query two databases in Monetdb - mysql

Im using monetdb and i have two databases on it "mydb" and "test".
I want to get a sub-set of values from 'mydb' into 'test'.
My code:
insert into test.result
select sum(chargfeeprepaid) from mydb.data where callingpartyno = 628388881507
union
select sum(chargefeeprepaid) from mydb.sms where callingpartyno = 628388881507;
This works fine in MySQL...but in Monetdb i get the error: INSERT INTO: no such scheme 'test'.
Where did i go wrong and what is the correct syntax to do this in monetdb?
Greetings Seleen

There is no way to do this in MonetDB. Every Database is served by it's own process (mserver) and there is no sharing between them.
If you want to migrate data from one database to another you have to either copy the data using the copy commands (see http://goo.gl/OXkto) or dump the data as sql inserts using the dump commands ( http://goo.gl/5Bfrf and http://goo.gl/EuPwE).

Related

Is it possible to make the insert command from existing table data

I have table which has a few data.
name score
1 AAA 100
2 BBB 98
3 CCC 85
Now I want to make the insert sentence such as
insert into pepolescore(name,score) VALUE("CCC",85)
automatically.
Is there any command to do this or any function ? by mysql commandline or phpmyadmin.
MySQL queries can address another schema on the same MySQL Server instance by using qualified table names. See https://dev.mysql.com/doc/refman/8.0/en/identifier-qualifiers.html
But this does not work if the tables are on separate MySQL Servers. A given SQL query can only address schemas on the same server.
Here are a few workarounds:
Use mysqldump to export data from one table and then use mysql to import it to the other table on the other instance. You need to be careful not to let mysqldump output the DROP TABLE command, so read about the options here: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html
MySQL supports a table engine called FEDERATED, where a table can function as a sort of proxy to a table on another MySQL Server. Then you can use INSERT ... SELECT syntax as if the tables were co-located on the same MySQL Server. The Federated engine has limitations, so read https://dev.mysql.com/doc/refman/8.0/en/federated-storage-engine.html and its subsections to learn more.
Use a community tool such as pt-archiver to copy data from one MySQL instance to the other. Read the manual to learn more: https://docs.percona.com/percona-toolkit/pt-archiver.html
Write your own custom code in a client application. Create two connections, one for each MySQL Server. Fetch query results from the first server, and store the resulting rows in variables in your application. Then use these rows as the tuples to insert using the second connection to the other MySQL Server. This involves writing more code, but you get a lot of flexibility.

How can I copy a table from one database to another database along with its data?

I have two separate databases installed on the same server. I name the representation as db1 and db2. I have a table named sample_table in my db1 database. I am trying to copy this table with its records to my db2 database with the following queries:
CREATE TABLE db2.sample_table LIKE db1.sample_table
insert into db2.sample_table select * from db1.sample_table
As a result of my research, I found that this method works in most places. However, when I type and run my query from the db2 console, I am having a user permission problem for db1. The query might be running, but should there be a configuration link between these two databases? If so, how can I get this link? What are the alternative solution methods I can overcome this problem?

how to insert table data from one user to another in different machines in mysql

I want to insert the data into one of the tables of a different user and a different database.
e.g.,
First DB
ip:ip1
user:user1
b:db1
Second DB
ip:ip2
user:user2
db:db2
So, I want to insert one of table's data of first DB into second DB.
You should try with
SELECT INTO OUTFILE
http://dev.mysql.com/doc/refman/5.0/en/select-into.html
and after that you can use
LOAD DATA INFILE
http://dev.mysql.com/doc/refman/5.0/en/load-data.html
You can try SQLyog's 'Copy Database to different host/Database' to copy from one MySQL server to another. Select the Database you want to copy and then Select Database -> Copy Database to different Host/DB to copy a database (with all or selected items of its table structure as well as the data) to another database (which may be located in another host).
You have to do 2 mysql_connect, which return the connection.
Within your mysql_query where you insert the data you have to put your reference as second parameter
Like:
$db2 = mysql_connect('ip1', 'mysql_user', 'mysql_password');
mysql_query ( "INSERT INTO *.....", $db2 )
$db1 = mysql_connect('ip2', 'mysql_user', 'mysql_password');
mysql_query ( "INSERT INTO *.....", $db1 )
If your using Objects (which you should use) you just have to save the reference and pass it all queries executed. Then you can just make 2 DB objects with different IP's.
You may try to attach remote tables using FEDERATED storage engine, if your current version of MySQL is built with --with-federated-storage-engine
Use SHOW ENGINES; to see if the engine is supported in your installation.
Unfortunatelly, I have not yet tried that myself, and can not share any experience.

Select from second MySQL Server

I would like to select data from a second MySQL database in order to migrate data from one server to another.
I'm looking for syntax like
SELECT * FROM username:password#serverip.databaseName.tableName
Is this possible? I would be able to do this in Microsoft SQL Server using linked servers, so I'm assuming it's possible in MySQL as well.
You can create a table using FEDERATED storage engine:
CREATE TABLE tableName (id INT NOT NULL, …)
ENGINE=FEDERATED
CONNECTION='mysql://username:password#serverip/databaseName/tableName'
SELECT *
FROM tableName
Basically, it will serve as a view over the remote tableName.
There are generally two approaches you can take, although neither of them sound like what you're after:
Use replication and set up a master/slave relationship between the two databases.
Simply dump the data (using the command line mysqldump tool) from the 1st database and import it into the 2nd.
However, both of these will ultimately migrate all of the data (i.e.: not a subset), although you can specify specific table(s) via mysqldump. Additionally, if you use the mysqldump approach and you're not using InnoDB you'll need to ensure that the source database isn't in use (i.e.: has integrity) when the dump is created.
You can't do this directly, but as someone else alluded to in a comment, you can use mysqldump to export the contents of a table as a SQL script.
At that point you could run the script on the new server to create the table, or if more manipulation of the data is required, import that data into a table with a different name on the new server, then write a query to copy the data from there.

Copying MySQL table data to another table

I want to copy the data from one MySQL table to another table. The source table contains 30 million records. the SQL connection gets lost when I tried to copy the data using the SQL query
INSERT table2 SELECT * FROM table1
Is there any external tool avaliable to do this job from the shell
Thanks
Sree
The mysql command line tool should be able to handle this just fine.