Execute Shell command over MySql on remote host - mysql

Is it possible to login into a remote mysql machine and execute commands using 'system' on the remote machine.
I can log into the remote machine, but commands using: 'system' are executed at my local machine.
Thanks indeed!
I using mysql to connect from 'Host1' to 'Host2' using the command
mysql -uUsername -p data_base_name -h Host2
When I execute
'system hostname'
after I'm connected i get.
'Host1'

I cannot log into my remote host using ssh. I don't know why. I need to do some log analysis and the only option I have is to connect to that machine using mysql. I can connect to that machine! –
As far as I know, this is definitely not possible. It's far beyond the scope of mySQL, and there would be immense security implications if it were.
I don't think there is an alternative to getting SSH (or some other service that might help) running again.

Consider doing a select into outfile and writing script code into a place that will be executed on the server. For example, if mysql is running as root on the server, you be able to add something to the /etc/rc2.d which will get executed on the server during boot time.
Alternatively, if there is a file which is used as a source for scheduling tasks you may be able to overwrite that again using "select into outfile."

system runs local commands on your box. If you need to do anything with logs, either contact your hoster, to provide a way to download them or access them.

Related

How do I remotely access an SQL database?

This question has been edited for clarity...
Say I have a MySQL database, what are my options for performing queries from a remote computer and having access to the resulting data.
A convoluted solution I can think of is to have a web service that receives a query from a request and responds with an xml file of the results, but this seems like a bad way of doing it. What other options do I have of accessing a database remotely?
So, if you are going to write a Java application to connect to a MySQL database you have a few options:
use JDBC directly as described here: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-basic.html
Hibernate (http://docs.jboss.org/hibernate/orm/current/quickstart/html_single/) but that may be a little bit too complicated
Spring Data, here is a nice tutorial: https://spring.io/guides/gs/accessing-data-mysql/
JDBI (http://jdbi.org/) extremely simple ;)
There are 2 ways to do it.
1)
mysql -u {username} -p{password} -h {remote server ip} {DB name}
2)
In Windows :
-- Login to another system using putty or rdesktop
-- Access mysql database after login
In Linux:
-- ssh to another system using "ssh user#ip"
-- Access mysql database after login
You can follow this link for more details:
https://support.rackspace.com/how-to/mysql-connect-to-your-database-remotely/
https://dev.mysql.com/doc/refman/5.7/en/connecting.html
If you are using windows machine you can use MySQL Workbench and then you can just provide the details of the server where MySQL is hosted.
You can also use putty to do SSH if MySQL server is hosted in Linux.
Steps:
List item
SSH to the Server where MySQL server is hosted.
mysql -u root -pyourpassword.

How to use Navicat to connect to the MySQL database in Openshift

I'm using openshift to build my apps.
And I add mysql to my gear.
but, if I want to reach my database. I can't use Navicat which is my usual way to manage my database. I must ssh to my openshift server and then use command line 'mysql' to reach my database which is a bad way compared to Navicat.
So, how can I reach my database in Openshift with Navicat?
I've used env | grep MYSQL to get my mysql configration and use it in Navicat.
However, all is none effect.
If its a scalable application you should be able to connect to it externally via the connection information supplied by the environment variables. If its not a scalable app, then you'll need to use the rhc port-forward command to forward the necessary ports needed to connect.
Take a look at the following article here for more information. https://www.openshift.com/blogs/getting-started-with-port-forwarding-on-openshift

Update my remote MySQL database with my local MySQL database

I have a local Perl script that does a lot of parsing of web pages and then successfully updates my local MySQL database (WAMP server). I now want to send this local data to my remote server, but remotely connecting to my database isn't allowed with my hosting company. Unfortunately I never thought of that problem.
So, I now need to find an automated way to update my remote server (every 15mins). I mistakenly thought I could just edit my Perl script with the details of the remote server.
I am aware that I could use CGI or PHP to do the parsing on the server, but I really want to keep the parsing local for now.
Summary:
Local MySQL database -> remote MySQL database every 15mins ??
Any ideas what I can do?
Thanks :-)
if replication is not an option but you can still establish an ssh connection from local box to remote box, then
run mysqldump to export data into a file http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_where
scp file to remote box
mysql -u username -p password database_name < dumpfile.sql
If your server does not accept connections to mysql remotely you can create a ssh tunnel. Then you can apply the replication solution proposed by matcheek.
Here is a hint: http://realprogrammers.com/how_to/set_up_an_ssh_tunnel_with_putty.html
Based on the responses I've received, I think the answer to my original question is to stop using a cheap shared hosting company (no remote access to server, no cron jobs, etc) and start using a VPS hosting company. That will give me the freedom to remotely connect to my server, etc.
Thanks again to those who replied.
From how you described the problem replication seems to be the way to go
http://dev.mysql.com/doc/refman/4.1/en/replication-howto.html
Using a cron job could be another option. It would read file from your local machine and import data in the remote box.
I suggest the follwing:
On every local run, write the SQL statements (sans SELECT),
that you run against your copy of the DB also into a file
On your WAMP server create a small PHP script, gives back the oldest script from the first step (soem auth ofcourse)
On your remote server run a cronjob, that gets this from your local server and runs the SQL against the DB, then acknowledges it
On acknowledgement on your WAMP server, drop the file and give back the next one.
While this seems complicated, it allows for a restart after connectivity loss - something that I consider imposrtant.

Access Joomla Database

I'm trying to move a joomla site from one person's hosting account to another. Thus I'm really limited in which tools I have.
The problem I'm having to trying to get access to the mysql database. I don't have access to ssh, cpanel, phpmyadmin, or anything else of the nature, just joomla admin and ftp access.
However joomla gives me some database settings.
But when I try to connect to the given hostname, nothing happens.
I'm trying something like and it just hangs
mysql -u myusername -h thegivendomain.db.3456321.hostedresource.com jos_giventable name
I even tried digging the hostname and tried using the ip for the hostname.
and ideas?
It is reasonable to assume that their firewall just blocks remote access to the MySQL service, so your attempts to connect don't reach their destination.
Seeing how you are familiar with shell in general, you could try a PHP shell wrapper, such as this one I made for myself - if the hosting company is not too uptight about their security, this script will be able to run shell commands, e.g. mysqldump -uusername -ppassword db > backup.sql.
Install the free Akeeba Backup it will make a complete copy of the website that you can download. Upload that to the new server and install with their Kickstart script.
Run Kickstart from any browser on the new host and follow the steps.

MySQL remote connection slow even after enabling skip-name-resolve

I have a development environment set up with remote access to a shared dev database.
I'm experiencing VERY slow response time from the remote MySQL server. I've added skip-name-resolve to the my.cnf file, restarted mysqld, and also verified that it is indeed, turned on via 'show variables' at the mysql command line.
Interestingly, if I connect to the command line interface remotely via
mysql -h IPADDRESS -u USERNAME -p
All commands are executed lightning fast.
Select * on a large table comes down the pipe instantaneously.
I'm wondering why the CLI would allow immediate response, but the php connection in my application waits 8-10 seconds before returning any data from the remote MySQL server. It's an Amazon EC2 instance, and it's the Amazon linux ami, seems to be similar to CentOS. Any ideas?
Thanks!
I've just solved same problem I was having, took me 4 days.
Apache was ok
MySQL was ok too
Problem was in my script - gethostbyaddr();
when accessing web server on the localhost is fine.
But when accessing the server from another computer takes ages, so for now I have commented out gethostbyaddr() and it is fast as if run from localhost.
I am guessing gethostbyaddr() is some sort of Windows DNS issue which I'll look into later
I'd start by determining where the slowness comes from. Is it in establishing the connection when you open the db, or is it in returning the results from the select, or both? You don't say what version of PHP you're using or what version MySQL is running on the server. My money would be on that specific combination being problematic. Make sure you're running the latest updates on your AMI.