I am pretty much new to bcp but I researched quite a bit and can not find any resource that says where we are actually sending the user name and password to the database with this command. So everyone can access the database?
bcp AdventureWorks2008.HumanResources.Employee out C:\Data\EmployeeData.dat -T
bcp AdventureWorks2008.HumanResources.Employee out C:\Data\EmployeeData.dat -T -c -U<login_id> -P<password> -S<server_name\instance_name>
You aren't sending the username and password with the -T argument. In fact, it won't send any specified username and password to SQL Server if -T is present in the command line.
-T tells BCP to use Windows Authentication to connect to SQL Server. It will operate as the user who's running the command.
[-U login_id] [-P password]
Source: http://technet.microsoft.com/en-us/library/aa174646(v=sql.80).aspx
sample query with db credentials
bcp "SELECT * from yourtable" queryout c:\StockItemTransactionID_c.txt -c -Uusername -Pdbpassword -Sinstance -dYourDBName
Removing -T has worked for me.
Related
When executing any one of the following commands:
osql -E -S ComputerName\InstanceName
osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt
osql -E -q "SELECT * FROM Northwind.dbo.Shippers"
osql -E -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt
I am getting the following error:
[SQL Server Native Client 10.0]SQL Server Network Interfaces: Connection
string is not valid [87].
[SQL Server Native Client 10.0]Login timeout expired
[SQL Server Native Client 10.0]A network-related or instance-specific error
has occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL Server
is configured to allow remote connections. For more information see SQL Server
Books Online.
However, I am able, without issue to login and run SELECT queries from SSMS.
How do I run queries against SQL Server 2008 using osql?
Do you have your logged in account set up as a user in SQL Server?
I usually work with specific accounts and SQL Server logins instead of Trusted Logins, and then just specify the database coordinates on the command line with the -S, -D, -U, and -P options:
osql -S %SERVERNAME% -U %USERNAME% -P %PASSWORD% -d %DBNAME%
For instance, if your server name is MyServer\SQL2008 and your user name is Foo and your password is Bar and your database is MyDB, then you'd use this:
osql -S MyServer\SQL2008 -U Foo -P Bar -d MyDB
And then continue on with the rest of your options after that.
If you really want to use your Trusted connection, you need to go to SQL Server Management Studio, and ensure your current Widows Login is added as a user and given appropriate permissions to your database, etc.
In SSMS, connect to your server manually (the 'sa' user and password perhaps), and then expand the "Security" node and look at the logins. If your currently logged in Windows User isn't listed, you'll want to right-click, add new Login, and add your current user.
Then you should be able to run with a Trusted Connection.
You have to run all command in a single line
like this
osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt
or
osql -E -S ComputerName\InstanceName -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt
Now you have to see if you can log in SQL Server or if the service is up or even if the TCP/IP protocol is enable
Use the value in the Server name: field for ComputerName\InstanceName. (e.g. MYPC\SQLEXPRESS)
Type:
osql -E -S MYPC\SQLEXPRESS
You will see the interactive prompt.
Then enter your commands:
USE pubs
GO
Also, you can use sqlcmd:
sqcmd -E -S MYPC\SQLEXPRESS
I am in the process of migrating my MySQL installation to Amazon RDS and they run MySQL Server version 5.6.12.
I got the client tools of version 5.6.13 and trying to use mysqldump for automated backups.
I always get the question to enter password which block my scripting of backups.
I looks like this:
ubuntu#ip-10-48-203-112:~$ mysqldump --user=dbadmin -pmysecretpassword -h someserver.eu-west-1.rds.amazonaws.com -p skygd > dump.sql
Warning: Using a password on the command line interface can be insecure.
Enter password:
I have tried with a configuration file .my.cnf
[client]
user=dbadmin
password=mysecretpassword
And it is picked up ok, if I run:
mysqldump would have been started with the following arguments: --port=3306 --socket=/var/run/mysqld/mysqld.sock --quick --quote-names --max_allowed_packet=16M --user=dbadmin --password=mysecretpassword
But still same question about enter password.
Are there a bug in 5.6.13 that doesn't allow automated login with password?
mysqldump --user=dbadmin --password=mysecretpassword -h someserver.eu-west-1.rds.amazonaws.com skygd > dump.sql
you typed -p at the end of the line
It is a better option to mention mysql password at the end of the first command.
mysqldump -uUsername -p"space-here"Databasename -h"space-here" Hostname >xyz.sql
And for database import use
mysql -uUsername -p"space-here"Databasename -h"space-here"Hostname
mysqldump -h xxx.xxx.xxx.xxx -u username -ppassword databasename > C:\path\to\store\file
It seemed to work as it paused while the file was downloading, however no file appears once it completes.
Do I have something wrong in the command line?
Use like this:
mysqldump -P3306 -h192.168.20.151 -u root -p database > c:/my.sql
Hope to help you:)
Edition for linux
mysqldump -u root -p databasename > ~/Downlaods/filename.sql
Simply run mysqldump -h xxx.xxx.xxx.xxx -u username -ppassword databasename > C:\path\to\store\file from the command prompt on your local machine.
I don't understand why you involve ssh in your question but...
First try the same command without redirecting it to a file to see that you can connect to the database.
Second make sure that you can write to that location (try to create and edit a file in the same path).
If those to work your command should work.
I have this command
sqlcmd.exe -E -i "C:\joe-db-scripts\joe-db-tasks.Install.sql"
and I need to add the specific non-standard port of 32001. How do I do that? I was thinking of some flag like -p or something but I don't know the syntax.
According to this MSDN link, you'd use -S tcp:servername,32001.
That's it: How to Connect to the Database Engine using sqlcmd. Something like this:
sqlcmd -S ComputerA,1691
Following solution is working for me in SQL Server 2008 and above.
sqlcmd -S "hostname or IP,port number" -U SA -P password
Mayo/23/2022, works
sqlcmd -S "hostname or IP,port number"
SQL Express 2019 from linux ubuntu client connecting to sql express on windows server
I am running the following command in a batch file:
osql -S dbname -U username -P password -i C:\inputSQL.sql -o C:\postMigration.log -n
The dbname, username, and password have all been set correctly.
However , when I run the batch file I get this output to the "C:\postMigration.log" log
[SQL Native Client]Shared Memory Provider: No process is on the other
end of the pipe.
[SQL Native Client]Communication link failure
My question is: what can cause SQL Server 2005 to throw this error? Is it a login issue?
Thanks!
Looks like you miss -H (host) param. Also note -o would work relative server's disk C: