Remote SQL Server - sql

I am using Microsoft SQL Server on my mac through a docker container. I currently have a database on my local host. I want to share it with another computer/user so that they can get access to the DBMS and use C#. They are getting a error something like 'the server is not found or accessible'.
How can i make the database remote?

search for my.conf file in container.
whereis mysql
change bind address value:
bind-address 0.0.0.0
Then try to connect remotely:
mysql -h <host-name> -P <port> -u <user-name> -p

Related

how to check ssh tunnel opened by a Dbeaver client for a pg_dump task?

i actually use a dbeaver client to connect to a remote Postgres database.
dbeaver client use a bastion, by creating a ssh tunnel between localhost and bastion
(and then, bastion is connected to the database).
We have something like that
localhost (dBeaver) --> bastion --> postgres database
to make a backup of my database, dbeaver client use a command like :
pg_dump --verbose --host=127.0.0.1 --port=59914 --username=my-user --format=c -t public.dashboard my-database > /dump.sql
so, i deduce that dbeaver created a tunnel between my localhost 55914 to the remote port of the postgres database (5432)
All is well and works perfectly, but i'd like to understand how dbeaver created the ssh tunnel.
How can we check in Linux that it exist an opened tunnel from my 59914 local port to the remote postgres database, using interdemediary bastion machine ?
What is the command line to check that ?

Double tunnel hop ssh

I'm using WinSSHTerm to connect to a proxy, from which I then connect to a server hosting a data warehouse. I just can't figure out how to reproduce my Putty connection using a shell command.
Short recap:
I first connect to the proxy server which maps the port 5432 to my local port 10001. After that, i connect to the database server and map its 5432 port to my proxy's 5432 port, which I previously mapped to my 10001 port locally. I am then able to connect to the databse via a database manager locally.
To do so:
I created the following connection to my proxy server first.
I then added a tunnel from there to my localhost port 10001.
Once I'm logged in to the proxy server, I use the following command to connect to the database server and map its 5432 port to the proxy's 5432 port.
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
I'd like to leave putty and move to WinSSHterm, predefine some login commands for a specific server.
How may I reproduce the behavior above using a shell command?
Here's my initial try, which is unfortunately not working:
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Thank you
I was finally able to find the correct way to write it.
Loginc Cmds
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Cmd-line Args
-L 10001:localhost:5432

How can I use SSH tunneling to connect to a remote MySQL server?

I'm using SSH tunneling for the first time, so I'm trying to understand how to configure it.
I've got a remote Linux server that hosts a MySQL database that I'm trying to connect to. In order to access the MySQL database directly through a software that only recognizes local databases, I suppose SSH tunneling would be the right way to set up the access, correct?
Now, I'm trying to set up the tunneling on my 'home' computer which is running the software that's trying to access the MySQL database. My first question is whether this is reverse tunneling or normal tunneling? Secondly, is it local tunneling or remote tunneling?
Finally, from what I understand, my code is supposed to look something like
ssh -L 8080:mylinuxserver.mycompany.com:22 myuser#mylinuxserver.mycompany.com
Is this correct? Is my source port '22' since I'm using SSH and is my destination port 8080 (or is there something more appropriate)?
When I try to use the above code, I am able to login using my passphrase (since my key is already in the MyLinuxServer) but when I ping localhost:8080, it cannot find the host.
What am I doing wrong?
I've got a remote Linux server that hosts a MySQL database that I'm trying to connect to
The command should be:
ssh -L 8080:localhost:3306 myuser#mylinuxserver.mycompany.com
Where:
8080: is hte local port on your workstation
localhost: is corresponding to mylinuxserver.mycompany.com
3306: the MySQL port on above localhost.
then connect (from your workstation) to MySQL as:
mysql -h 127.0.0.1 --port=8080
Besides, ping localhost:8080 is wrong. Ping cannot work that way.
Try this:
ssh -f ssh_user#mylinuxserver.mycompany.com -L 3307:mysql1.example.com:3306 -N
Next, to access the mysql your trying to connect to:
mysql -h 127.0.0.1 -P 3307

How do you access an Amazon RDS instance from a chromebook?

I have accepted the "Chromebook challenge." So far, I have successfully ssh'ed into my new Google Compute Engine from ChromeOS's built in ssh terminal. But now I am faced with the task of connecting to an Amazon RDS (relational database service) instance that a consulting client has set up for me. I have found no tutorials how to do this. I don't know if I should be ssh'ing into the RDS, or what.
Has anyone else done this successfully?
Aha, so there is no way of ssh-ing to an RDS instance directly (Chromebook or otherwise), as Fredrick mentioned.
That said, I have accomplished all I needed by ssh-ing from my Chromebook into my Google Compute Engine, and then hopping from there to my RDS instance, using the standard:
me#myserver$mysql -h myrdsinstanceaddress -P 3306 -u root -p
So, the crux is that you have to ssh into some other server, and then work from there.
From the aws documentation.
Type the following command at a command prompt to connect to a DB instance using the MySQL utility. For the -h parameter, substitute the DNS name for your DB instance. For the -P parameter, substitute the port for your DB instance. Enter the master user password when prompted.
PROMPT> mysql -h myinstance.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u mymasteruser -p

Import a local SQL File To MySQL on a Remote Server Using SSH Tunnel

I have a connection between my localhost and a remote server using putty SSH tunnel.
Thats fine.
Now I need a command to get the sql file on my local machine i.e. c:\folder\test.sql and import it into mysql on the remote server
I thought maybe...
mysql -u prefix_username -p testpass -h localhost -P 3307 prefix_testdb
then do a command like
mysql -p testpass -u prefix_username prefix_testdb < c:\folder\test.sql
this command did not work.
How can I acheive this?
You should run this command
mysql -h host -u user_name -pPassword database < file.sql > output.log
file.sql contains the sql queries to run and output.log makes sense only when you have a query that returns something (like a select)
The only thing different I can see in your code is the blank space between the -p option and the password. If you use the -p option, you must write the password without leaving any blank space. Or you just can user the option --password=Password
I hope you can solve the problem
You will need to ssh to the remote machine with the mysql command appended:
ssh remote_user#remote_server mysql -p testpass -u username testdb < c:\folder\test.sql
1. mysql -h xxx -uxxx -pxxx . //login to the remote mysql
2. use DATABASE. //assign which db to import
3. source path/to/file.sql //the path can be your local sql file path.
Reference: Import SQL file into mysql
Use 'scp' to copy and mysql to insert to you local machine.
Syntax:
scp remote_user#remove_server:/path/to/sql/file.sql ~/path/to/local/directory
after you transfered the file use:
mysql -uYouUserName -p name_of_database_to_import_to < ~/path/to/local/directory/file.sql
mysql {mydbname} --host {server}.mysql.database.azure.com --user {login} --password={password} < ./{localdbbackupfile}.sql
As managed services, DevOps, and CI/CD workflows have become more popular by this point, most providers of those managed services want to remove the human error part of getting the connection strings correct. If you happen to be using Azure, AWS, GCP, etc, There usually is a page or terminal command that shows you these strings to help you easily integrate. Don't forget to check their docs if you're using something like that. They are auto generated, so they are most likely 'best practice' with spot-on correct syntax for the db version you may be using.
The above command is from "connection strings" on the product details page of my Azure Managed Mysql DB Server instance.
Not necessarily asked, but an fyi, a lot of those services auto generate templates for use in a lot of common connection scenarios:
{
"connectionStrings": {
"ado.net": "Server={server}.mysql.database.azure.com; Port=3306; Database=mytestdb; Uid={login}; Pwd={password};",
"jdbc": "jdbc:mysql://{server}.mysql.database.azure.com:3306/mytestdb?user={login}&password={password}",
"jdbc Spring": "spring.datasource.url=jdbc:mysql://{server}.mysql.database.azure.com:3306/mytestdb spring.datasource.username={login} spring.datasource.password={password}",
"mysql_cmd": "mysql mytestdb --host {server}.mysql.database.azure.com --user {login} --password={password}",
"node.js": "var conn = mysql.createConnection({host: '{server}.mysql.database.azure.com', user: '{login}', password: {password}, database: mytestdb, port: 3306});",
"php": "$con=mysqli_init(); [mysqli_ssl_set($con, NULL, NULL, {ca-cert filename}, NULL, NULL);] mysqli_real_connect($con, '{server}.mysql.database.azure.com', '{login}', '{password}', 'mytestdb', 3306);",
"python": "cnx = mysql.connector.connect(user='{login}', password='{password}', host='{server}.mysql.database.azure.com', port=3306, database='mytestdb')",
"ruby": "client = Mysql2::Client.new(username: '{login}', password: '{password}', database: 'mytestdb', host: '{server}.mysql.database.azure.com', port: 3306)"
}
}
You can use pscp to upload file to the server. Go to your command line and type this
pscp.exe c:\folder\test.sql usernameoftheserver#websitename.com:/serverpath