how can I make federated storage engine connection in oracle - mysql

I'm currently switching my project database from mySQL to oracle, and I'm new to oracle.
Previously, mySQL Query looked like this:
CREATE TABLE log_remote (
log_no NUMBER(11) NOT NULL AUTO_INCREMENT,
dttm DATETIME(3) NOT NULL,
log_code VARCHAR2(20) NOT NULL,
log_type VARCHAR2(255) NOT NULL,
product VARCHAR2(64) NOT NULL,
detail VARCHAR2(2048) NULL DEFAULT NULL,
hmac VARCHAR2(64) NOT NULL',
PRIMARY KEY (log_no, dttm)
) COLLATE='utf8_general_ci' ENGINE=FEDERATED
CONNECTION='mysql://dblink:project!dblink#${Ip}:3306/cli/cli_log'
Problem is, I don't know how to make this query
CONNECTION='mysql://dblink:project!dblink#${Ip}:3306/cli/cli_log'
in oracle SQL. I heard that I can't use federated storage engine connection in oracle
but I can't find how to make the equivalent query in oracle.
Can someone help me out? Thanks :)

I don't know MySQL so I Googled. It says that
The FEDERATED storage engine lets you access data from a remote MySQL database ...
If that's so, in Oracle you'd use a database link. Then access table(s) - which reside in another database - over the database link.
Here's an example. User - which creates the database link - has to have that privilege which means that privileged user (such as SYS, who owns the database) has to grant it:
SQL> grant create database link to scott;
Grant succeeded.
scott user will then create the DB link to user hr:
SQL> connect scott/tiger
Connected.
SQL> create database link dbl_hr
2 connect to hr
3 identified by hr
4 using 'xe';
Database link created.
Does it work?
SQL> select * from dual#dbl_hr;
D
-
X
SQL>
Yes, it works.

Related

Error while importing SQL database from local to server

I know this question has been asked before but I still couldn't get it fixed. I'm getting a #1046 error while importing my WP database from local to server. Here is what I get :
CREATE TABLE `wp_cntctfrm_field` (
`id` int(11) NOT NULL,
`name` char(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
MySQL a répondu (Translation: MYSQL responded) : Documentation
1046 - Aucune base n'a été sélectionnée(translation : no database was selected)
It's the first time I do it so I followed a tutorial but nothing seems to make it work.
You must select the target database you want to use to create/populate the database schema in.
You can select the target database at a global level for instance with Mysql Workbench in the left side, right hand click on the database you want to populate and select "Set as default schema".
You can also define the target database upon each SQL query.
For instance with your example, if the target database is named targetdb :
CREATE TABLE targetdb.wp_cntctfrm_field ( id int(11) NOT NULL, name char(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Please note that the target database must be created first with the appropriate CREATE DATABASE clause.
Hope this helps
You can use mysql -u <user> <DB_name> <<filename>
or add use <db_name>; at top of your dump file

How to Insert into another Database Server

Is it possible to INSERT query to another db server?
Current Db server: 192.168.59.2
Example:
Insert into 192.168.1.1.Testing.Student (id) values (1)
Looks like you need to use MySQL The FEDERATED Storage Engine. Per documentation
The FEDERATED storage engine lets you access data from a remote MySQL
database without using replication or cluster technology. Querying a
local FEDERATED table automatically pulls the data from the remote
(federated) tables. No data is stored on the local tables.
It kind a similar concept like Linked Server in Microsoft SQL Server.
Simply Use Generate Script Feature of the SQL server :
Follow Link
I'm afraid you can't do something like that. Maybe you should look into FEDERATED tables, where you can copy values to a table from one server to another.
You could have something like this on the table, which you're trying to map:
CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (id)
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='mysql://user#your_host:3306/federated/test_table';
This thread might help you.
Thank you for all the answers. I've answered my question by installing a trial version of navicat and export to excel then import to another db server. Thank you again guys!

MySql Remotely access database

I have a two DB server say Server-1 & Server-2, I have installed MySql yog into it, and the servers are able to connect with each other as I have already provided Grant privileges for the servers.
But, I need to build a query which can extract data from more than one servers like -
Select * from Server1.db.Table1, Server2.db.Table2
Is this possible in mysql, if yes, can you please help me to achieve the same.
Thanks
federated storage engine should help to full fill your requirement.
Follow link to enable Federated storage engine in your server from where you are accessing remote table.
--In Server1:
CREATE DATABASE fed_remote_db
CREATE USER 'fed_remote_user'#'%' IDENTIFIED BY 'fed_remote_password';
GRANT ALL ON fed_remote_db.* TO 'fed_remote_user'#'%';
CREATE TABLE fed_remote_db.fed_table(id INT,NAME VARCHAR(50));
--In Server2:
CREATE TABLE fed_remote_db.Server1_fed_table (
id INT NOT NULL AUTO_INCREMENT,
NAME VARCHAR(50) NOT NULL,
PRIMARY KEY (id)
) ENGINE=FEDERATED CONNECTION='mysql://fed_remote_user:fed_remote_password#Server1_IP:3306/fed_remote_db/fed_table';
SELECT *
FROM
fed_remote_db.Server1_fed_table a /* Remember Server1_fed_table table referring to remote server /,
fed_remote_db.server2_fed_table b / server2_fed_table table referring to local server */
WHERE a.id=b.id;
I believe you can convert above example for your requirements.

I need to join table from other database and sometimes other server

My project has its own database. Also, I use table of users, which is on other database. Two offices have their data on the same server, but third one has its own user table on other server.
So, in lots of queries I need to join either table some_db.users or other_server.some_db.users
What solution would you advise for this scenario?
I use MySQL.
There is Federated tables in MySQL:
The FEDERATED storage engine lets you access data from a remote MySQL
database without using replication or cluster technology. Querying a
local FEDERATED table automatically pulls the data from the remote
(federated) tables. No data is stored on the local tables.
First, you must have a table on the remote server that you want to access by using a FEDERATED table. Suppose that the remote table is in the sakila database and is defined like this:
CREATE TABLE test_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL
PRIMARY KEY (id)
)
ENGINE=MyISAM
DEFAULT CHARSET=latin1;
Next, create a FEDERATED table on the local server for accessing the remote table:
CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL
PRIMARY KEY (id)
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='mysql://fed_user:fed_user#197.186.1.199:3306/sakila/test_table';
Sample connection strings:
CONNECTION='mysql://username:password#hostname:port/database/tablename'
CONNECTION='mysql://username#hostname/database/tablename'
CONNECTION='mysql://username:password#hostname/database/tablename'
The basic structure of this table should match that of the remote table, except that the ENGINE table option should be FEDERATED.
Execute:
show variables like '%federated%';
to check if FEDERATED storage engine is available on your local server.
The table federated_table in localhost becomes virtual table of test_table in remote server.
Now you can use the JOIN between the tables in a DB in the localhost server. If there is a table called test in your localhost server, and you want to JOIN with the former sakila.test_table which is in the remote server, write a query like the one shown below:
SELECT * FROM `federated_table` JOIN `test`;
The federated_table in the query will actually refer to test_table in remote server.
On enabling FEDERATED Storage Engine
The FEDERATED storage engine is not enabled by default in the running server; to enable FEDERATED, you must start the MySQL server binary using the --federated option.
NOTE:
Optional storage engines require privileges and will fail to load when --skip-grant-tables is specified.
The result the entire db will fail to load and the following error will appear in the logs:
110318 21:37:23 [ERROR] /usr/local/libexec/mysqld: unknown option '--federated'
This in turn means that an upgrade from 5.x needs to be done in two steps if you have federated tables. Once with --skip-grant-tables and without --federated, the once without --skip-grant-tables and with --federated.
Source: The FEDERATED Storage Engine
Please mention the databse also.
In SQLServer you can use Linked sever. http://msdn.microsoft.com/en-us/library/ms188279.aspx
In MySQL, you can join tables from different databases using fully qualified names like
`database_name1`. `table_name1` JOIN `database_name2`.`table_name2`
But i fear, you cant join tables from different servers because for that you need to have two different connections and as per my knowledge there are no fully qualified connection names to be used in the query.
Alternatively, you can create local temporary table(s) on one of the servers and run the query there on. But in this case you will need to transfer data from one server to another. You can use MySQL GUI tool like SQLyog or MySQL admin, to transfer data from one server to another and to synchronize databases on two servers.
Hope it helps....
Federated tables are your solution for tables on other servers. They are very slow though if you perform joins on them.
If you just want to read data from another database on the same server you can use a view. This way you have all tables virtually in one database and you have to open only one connection in your application.
CREATE
VIEW `my_db`.`table_name`
AS
(SELECT * FROM `other_db`.`table_name`);

MySQL Error: #1142 - SELECT command denied to user

I'm having troubles with a certain query on one of my servers. On all other places I've tested it it works completely fine but on the server i want to use it it isn't working.
It's about the following SQL:
SELECT facturen.id AS fid,
projecten.id AS pid,
titel,
facturen.totaal_bedrag AS totaal,
betaald,
datum
FROM facturen,
projecten
WHERE facturen.project_id = projecten.id
AND projecten.eigenaar = '1'
ORDER BY datum DESC
This is the error code I get from it:
SELECT command denied to user 'marco'#'localhost' for table 'projecten'
The tables:
facturen:
CREATE TABLE IF NOT EXISTS `facturen` (
`id` int(11) NOT NULL auto_increment,
`project_id` int(11) NOT NULL,
`datum` int(11) NOT NULL,
`lever_datum` int(11) NOT NULL,
`totaal_bedrag` decimal(9,2) NOT NULL,
`btw` decimal(9,2) NOT NULL,
`bedrijf` varchar(40) NOT NULL,
`contactpersoon` varchar(60) NOT NULL,
`adres` varchar(60) NOT NULL,
`postcode` varchar(7) NOT NULL,
`plaats` varchar(30) NOT NULL,
`betaald` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200006 ;
projecten:
CREATE TABLE IF NOT EXISTS `projecten` (
`id` int(11) NOT NULL auto_increment,
`titel` varchar(80) NOT NULL,
`eigenaar` int(11) NOT NULL,
`creatie_datum` int(11) NOT NULL,
`eind_datum` int(11) NOT NULL,
`totaal_bedrag` decimal(9,2) NOT NULL,
`btw` decimal(9,2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=201200004 ;
The strange part is that every other query on both the 'projecten' table and the 'facturen' table works completely fine, also this query works fine on two other servers of mine.
I faced the same situation but its funny that reason for the error was due to the use of the incorrect database or schema name.
Its true that multiple issues can lead to error you have mentioned.
You need to grant SELECT permissions to the MySQL user who is connecting to MySQL
same question as here Error: select command denied to user '<userid>'#'<ip-address>' for table '<table-name>'
see answers of the link ;)
This error also arises for a syntax error occurred due to tablename aliasing.
For instance, when executing below query,
select * from a.table1, b.table2 where a.table1= b.table2
below error occurs:
MySQL Error: #1142. Response form the database. SELECT command denied to user "username#ip" for table "table1"
Solution : Syntax to alias tablename should be used properly, syntax solution for above instance:
select * from table1 a, table2 b where a.table1= b.table2
I had this problem too and for me, the problem was that I moved to a new server and the database I was trying to connect to with my PHP code changed from "my_Database" to "my_database".
This is th privileges issue in your database users. first check and grant permission to user
'marco' in localhost
I just emptied my session data then it worked again. Here is where you find the button:
So the issue I ran into was this... the application I used to grant the permissions converted the Schema.TableName into a single DB statement in the wrong table, so the grant was indeed wrong, but looked correct when we did a SHOW GRANTS FOR UserName if you weren't paying very close attention to GRANT SELECT vs GRANT TABLE SELECT. Manually correcting the Grant Select on Table w/ proper escaping of Schema.Table solved my issue.
May be unrelated, but I can imagine if one client does this wrong, another might too.
Hope that's helpful.
I run into this problem as well, the case with me was incorrect naming . I was migrating from local server to online server.
my SQL command had "database.tablename.column" structure. the name of database in online server was different. for example my code was "pet.item.name" while it needed to be "pet_app.item.name"
changing database name solved my problem.
This error happened on my server when I imported a view with an invalid definer.
Removing the faulty view fixed the error.
The error message didn't say anything about the view in question, but was "complaining" about one of the tables, that was used in the view.
You need to give privileges to the particular user by giving the command mysql> GRANT ALL PRIVILEGES . To 'username'#'localhost'; and then give FLUSH PRIVILEGES; command.
Then it won't give this error.., hope it helps thank you..!
If you using/connect more then one databases then you should use same DB_USERNAME for all databases
I had the same issue solved by using same DB_USERNAME for all databases ,
because i was use/connect multiple databases in same project and every database DB_USERNAME was different so when i run the query select,update, delete etc from multiple database then was get this error.
because if you use more then one table in query and the database DB_USERNAME is different you will get this error.
I had this error, because I copied stored procedure from localhost and there the db name was different then on the server I wanted to use it. It took me a couple of hours to figure out, why I don't have permissions to execute the procedure... Check you db names pls :D Hope someone finds this useful...
I tried to issue SELECT * FROM information_schema.INNODB_METRICS; on a so-called "budget host." I got 1142 because reading that particular system table requires the PROCESS privilege and the user didn't have it. I had to fool around to figure out it was PROCESS and not some other privilege that was missing.
(No, the "budget host" won't grant that priv to the user. They probably don't want their customers to see how ridiculously overloaded their servers are. Because MySQL licenses are expens .... wait, no they're free.)
In MySQL query browser go to Tools tab>MySQL Administrator > User Administration and then give the privileges to user.