How to Merge Databases on Google Cloud SQL? - mysql

I am exploring Google Cloud SQL and I need to have the ability to merge data bases for continuous integration reasons but I cannot figure out how (on a Cloud SQL instance).
The instance contains three databases: development, staging, and production.
I would usually run a simular command on a server instance running MySQL with the following:
mysqldump -n -t -u <myUSER> --password=<myPASSWORD> development | mysql -u <myUSER> --password=<myPASSWORD> staging
If I try to run this command via a server instance that has access to the (remote) dB instance, I get the following error:
mysqldump: Got error: 1045 (28000): "Access denied for user
'myUSER'#'localhost' (using password: YES)" when trying to
connect
I am thinking I need to pass an IP address in the command(??) - But I do not know how.
SO my question is how would I connect to a Google Cloud SQL instance via another server instance that has permissions to access the (remote) database server?
Any help will be greatly appreciated!
-j

I just needed to pass -h <DB-IP> in the command.
i.e.:
mysqldump -n -t -u <myUSER> -h <XXX.XXX.XX.XXX> -p<myPASSWORD> development | mysql -u <myUSER> -h <XXX.XXX.XX.XXX> -p<myPASSWORD> staging

Related

how to logon to mysql as a non localhost user

I have two users set up, one is testuser#localhost and one is testuser#111.111.11.111 for example. When I do the following command from ubuntu 20.04 prompt:
mysql -u testuser -p it prompts me for a password and logs me on to testuser#localhost. If I try something like mysql -u 'testuser'#'111.111.11.111' -p it assumes it is localhost and gives an error message Access denied for user 'testuser#111.111.11.111'#'localhost'. How do I specify and log on as a non localhost user?
I found the command, it is mysql -h 111.111.11.111 -u testuser -p. For some reason I am not able to logon with the user with the ip address specified. I keep getting a 2003 error which indicates some kind of configuration issue. Can't connect to MySQL server on ' server ' (10061) indicates that the network connection has been refused.
Let me edit this to make more sense in what I am trying to do. Eventually there will be two mysql servers, say one on ip address 111.111.11.111 and one on 111.111.11.112 for example. I want to be able from a php script running on 111.1111.11.111 be able to access data from a table on 111.111.11.112 for example. I am just now first trying to logon to the first server which is running a mysql database using the user name and ip address of the host.
I will post the answer to the original question which is to include a host parameter in the logon command as follows:
mysql -h 111.111.11.111 -u testuser -p

Sqlalchemy and DBvisualizer failing with port fowarding

To connect to our database, we need to use port forward to connect to the remote instance.
ssh -i [ssh Key] -f -N -L [local port]:[host]:[remote port] [user]#[remote ip]
Afterwards, I can then use this command to access the remote database.
mysql -h 127.0.0.1 -P [local port] -u [database user] -p
If I use the local settings in something like SQLAlchemy or DbVisualizer however, I get
Access denied for user [user]#'10.0.1.70' (using password:
YES)
I know the password is correct, so what am I missing in my understanding? What is the difference here between the cli and these other interfaces?
For DbVisualizer, have you tried specifying Database Server as "localhost", as described here:
http://confluence.dbvis.com/display/UG100/Using+an+SSH+Tunnel
Best Regards
Hans Bergsten (DbVisualizer developer)

Querying remote MySql database with bash

I'm trying to query remote database with the following script.
some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -D$some_db -e "$checkSearch");
This works for me locally however whenever i try to run bash script to remote AWS server I get error
ERROR 1049 (42000): Unknown database 'somedb'
Any hints?
P.S. The database exists for sure. I can connect to it via MySQL client.
You need to add the parameter for remote host -h
some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -h REMOTE_IP -D$some_db -e "$checkSearch");

Can not connect to AWS RDS mysql from SQLWORKBENCH

I am new to AWS. I followed AWS quick start documentation and created my Web server and Database server. I can connect my Web server from my browser and ssh client. But i couldn't connect my MYSQl database from SQL workbench or MySQL yog.
I tried connecting it through command line from my web server its connecting. I thought its due to some user access problem and tried changing the user access by query and it says access denied for giving grant permissions. please suggest me the how to connect to AWS RDS from remote machine(any sql gui tool).
I'm not sure if it's proper way, but you can create ssh tunnel like that:
ssh -N -L 6033:RDSendpoint.rds.amazonaws.com:3306 -i /path/tokey/aws-key.pem ec2-user#EC2IPAddress
And then connect using mysql -h 127.0.0.1 --port=6033 -u yorrdsuser -p from local.

ERROR 1045: Transferring SQL database from one server to another

I have taken the the following steps to transfer my sql database but yet I receive an error on the importing of the database onto the new server. It does not seem to recognize my username or password.
I think the problem is being caused by phpMyAdmin privilege settings. I am transferring my sql file from a server that runs phpMyAdmin (hostgator) to an unmanaged web server.
Here are the steps I took
mysqldump -u root_wrdp1 -p --opt root_wrdp1 > root_wrdp1.sql
Enter password:
I then scp'd the sql file to my new web server (that does not run phpMyAdmin).
scp rbl91_wrdp1.sql root#ip.of.the.server:~/
Then I did the updating of the database on the web server without phpmyadmin...
root#www:~# mysql -u root_wrdp1 -p root_wrdp1 < ~/root_wrdp1.sql
Enter password:
ERROR 1045 (28000): Access denied for user 'root_wprd1'#'localhost' (using password: YES)
The support by the site offered this advice but I have no idea how to implement the steps.
It's possible you have to review the authorization locations, such as the source location (IP) of the remote side.
Using phpMyAdmin i believe the page is Priviliages , and you will also
need to flush them after changing.
Thanks Support
It's a simple authentication problem. Most likely the "root_wrp1" account or password are set up incorrectly on the destination machine. You can check it just by trying to log in without importing the dump file:
$ mysql -u root_wrdp1 -p root_wrdp1
The account and password need to be set up and have adequate permissions to the database before you can restore the dump file.