Two servers, one on Windows server + WAMP, one on Linux Debian + MySQL
I would like to understand why I don't get the same result from these two following ways:
From a phpmyadmin (MySQL on linux) I import a sql file
From MySQL (on windows server) I launch this powershell
Script file content:
$mysqlpath = "C:\wamp\bin\mysql\mysql5.6.12\bin\"
$username = xxx
$password = xxx
$backuppath = "C:\"
$backupfile = $backuppath + "file.sql"
CD $mysqlpath
&cmd /c "mysql -u $username -p$password -h 0.0.0.0 < $backupfile"
CD C:\
NOTE: (0.0.0.0 is Linux server IP address)
Why i don t get the same result from these two ways?
How can I set up the powershell file with the right parameters to get the same results that the first solution ?
In using WinRM and ssh, can I lauch my powershell file on windows to execute via ssh the mysql command on linux server ?
Related
I work with Api Manager version 3.0.0 and implement database, MySQL version 5.7.28 in Ubuntu 18.04.3 LTS in localhost with this steps:
In MySQL, create two databases, shared_db and apim_db.
Create a new user for MySQL and add privileges for the user a create in the databases, shared_db and apim_db.
In terminal execute this lines:
mysql -u **NEWUSER** -p -Dshared_db < '[API-MANAGER]/dbscripts/mysql.sql';
mysql -u **NEWUSER** -p -Dapim_db < '[API-MANAGER]/dbscripts/apimgt/mysql.sql';
Create a JAR with this:
apt-get install libmysql-java
In this path /usr/share/java execute:
cp mysql.jar [API-MANAGER]/repository/components/lib
In [API-MANAGER]/repository/conf, the file deployment.toml, edit this lines:
deployment.toml
[database.apim_db]
type = "mysql"
url = "jdbc:mysql://localhost:3306/apim_db?useSSL=false"
username = "NEWUSER"
password = "PASS"
[database.shared_db]
type = "mysql"
url = "jdbc:mysql://localhost:3306/shared_db?useSSL=false"
username = "NEWUSER"
password = ""
Restart to server and works, BUT necessarily use this ?useSSL=false.
So, my cuestion is: Why needs this ?useSSL=false? In production needs this lines?
Thanks.
I've used a golem pipeline to package & dockerize my app.
For starters, I am trying to deploy the app locally on windows pc using docker (also tried to run it on linux with a same problem). The app collects the data from a local SQlite database also running on my pc (which will be similar once deployed on a server).
When I run the app as a package, app functions alright.
But once I create a docker image & run it, the app launched but is unable to connect to my local sql database, returning this error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")
Connection to the database inside app looks like this:
con = dbConnect(RMariaDB::MariaDB(), dbname = "training_dash_db", user = "root", password = "", host = '127.0.0.1')
My docker file looks like this:
FROM rocker/tidyverse:3.5.3
RUN R -e 'install.packages("remotes")'
RUN R -e 'remotes::install_github("r-lib/remotes", ref = "97bbf81")'
RUN R -e 'remotes::install_cran("shiny")'
RUN R -e 'remotes::install_github("Thinkr-open/golem")'
RUN R -e 'remotes::install_cran("processx")'
RUN R -e 'remotes::install_cran("attempt")'
RUN R -e 'remotes::install_cran("DT")'
RUN R -e 'remotes::install_cran("glue")'
RUN R -e 'remotes::install_cran("htmltools")'
RUN R -e 'remotes::install_cran("shinydashboard")'
RUN R -e 'remotes::install_cran("shinydashboardPlus")'
RUN R -e 'remotes::install_cran("lubridate")'
RUN R -e 'remotes::install_cran("dplyr")'
RUN R -e 'remotes::install_cran("purrr")'
RUN R -e 'remotes::install_cran("plotly")'
RUN R -e 'remotes::install_cran("DBI")'
RUN R -e 'remotes::install_cran("tibbletime")'
RUN R -e 'remotes::install_cran("tsibble")'
RUN R -e 'remotes::install_cran("shinyWidgets")'
RUN R -e 'remotes::install_cran("leaflet")'
RUN R -e 'remotes::install_cran("pool")'
RUN R -e 'remotes::install_cran("RMariaDB")'
RUN R -e 'remotes::install_cran("roxygen2")'
COPY K2dashboard_*.tar.gz /app.tar.gz
RUN R -e 'remotes::install_local("/app.tar.gz")'
EXPOSE 80
EXPOSE 3306
CMD R -e "options('shiny.port'=80,shiny.host='0.0.0.0');K2dashboard::run_app()"
Thanks.
Here are the issues I can see:
You're using 127.0.0.1 as a host for your database. Once in the container, this address refers to the inner IP of the container, not the one from your host machine / another container. So your app can't access the host DB.
You haven't installed the drivers for MariaDB inside your container
Here are solutions:
You can use the r-db docker image as a source : http://colinfay.me/r-db/, which contains drivers for MariaDB: http://colinfay.me/r-db/mariadb-rmariadb.html
Depending on wether your MYSQL is in a docker or not, but you can create a Docker network, and plug your mysql container and your golem container on this network. Then use host = "my-network". See the r-db documentation for information about that: http://colinfay.me/r-db/intro.html#creating-docker-network, and http://colinfay.me/r-db/mariadb-rmariadb.html for the mariadb part
You want to access the database on your machine from inside the container: see How to access host port from docker container for information about that.
In my application(on Linux) I receive a .DAT file daily which I'm supposed to Load into a remote SQL server Table. As per requirement, I should Truncate(or Delete all rows) from this table before I load the .DAT file into the table.
I have tried below command
mysql -h <servername>,<port-number> -u <username> -p <password> -e "DELETE from <DB_name>.<Schema_name>.<Table_name>"
but it fails with error
-ksh: mysql: not found [No such file or directory]
I reached out to a Linux expert in my team and he did a find for "mysql" and from the result he interpreted that MYSQL is not installed in the Local Linux machine.
Further I tried BCP
bcp "Delete from [DB_name].[schema_name].[table_name]" queryout <output_file_full_path> -S <servername>,<port-number> -m 0 -e <error_file_full_path> -T -c -t '|'
which failed with below message
Starting copy... SQLState = S1000, NativeError = 0 Error =
[Microsoft][ODBC Driver 11 for SQL Server]BCP host-files must contain
at least one column SQLState = S1000, NativeError = 0 Error =
[Microsoft][ODBC Driver 11 for SQL Server]Unable to resolve column
level collations
I understand BCP queryout requires some result to be stored into file but Delete does not return any thus the BCP failure.
Thus I want to know if there is any alternate to Delete data from Remote SQL Table via Local Linux machine.
If you are trying to connect to Microsoft SQL Server, I recommend you use sqlcmd/bcp + ODBC Driver.
To do so:
Download the ODBC Driver from here: https://www.microsoft.com/en-us/download/details.aspx?id=53339
Download the sqlcmd/bcp tools from here: https://www.microsoft.com/en-us/download/details.aspx?id=53591
Restart your Windows machine and connect to SQL Server using the following:
sqlcmd -S myserver -d Adventure_Works -U myuser -P myP#ssword -I
If you would like to use bcp, check out some examples here:
https://msdn.microsoft.com/en-us/library/ms162802.aspx
If you are on Linux, follow this: https://blogs.msdn.microsoft.com/sqlnativeclient/2017/02/04/odbc-driver-13-1-for-linux-released/
I'm a little green at this, and I hope the issue I'm having is a simple one...edit: new information at bottom
I need to make a connection to a remote mysql (Amazon RDS) database.
After following a few tutorials, I have unixodbc and libmyodbc installed and configured on the client, but when I try to connect via isql, I get the error
[08S01][unixODBC][MySQL][ODBC 5.1 Driver]Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[ISQL]ERROR: Could not SQLConnect
The most confusing part about this error is that I'm not trying to connect to a local database, but rather to a remote one. I do not have a mysql.sock file on the client...this isn't the issue though is it?
I'm sensing a configuration error but I'm just not sure what it could be.
If I run odbcinst -j then the output is:
DRIVERS............: /etc/unixODBC/odbcinst.ini
SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
The content of /etc/unixODBC/odbcinst.ini is:
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib64/libmyodbc5.so
Setup = /usr/lib64/unixODBC/libodbcmyS.so
UsageCount = 5
[MySQL ODBC 515 Driver]
Description = ODBC 5.515 for MySQL
DRIVER = /usr/lib64/libmyodbc5-5.1.5.so
SETUP = /usr/lib64/unixODBC/libodbcmyS.so
UsageCount = 3
Please note that I had to make up this configuration myself, I did a find for libmyodbc* and found these two .so files, thus set up a driver for each of them. A search for libodbcmyS* yields:
/usr/lib64/unixODBC/libodbcmyS.so.1
/usr/lib64/unixODBC/libodbcmyS.so
/usr/lib64/unixODBC/libodbcmyS.so.1.0.0
So, I don't know what else that configuration could be.
The content of /etc/unixODBC/odbc.ini is:
[target_db]
Driver = MySQL
Server = [servername.com]
Port = 3306
Database = [databasename]
Option = 2
User = [username]
Password = [password]
I've tried different options in "Driver", changing it from MySQL, to MySQL ODBC 515 Driver, to the path to the .so file (eg: /usr/lib64/libmyodbc5.so) and all yield the same result.
I'm running:
odbcinst -i -d -f /etc/unixODBC/odbcinst.ini
Followed by:
odbcinst -i -s -l -f /etc/unixODBC/odbc.ini
Followed by:
odbcinst -s -q
Which prints out the name of my connection, ie [target_db]
Then, I try the connect:
isql -v target_db user password
or just
isql -v target_db
and get the error shown above.
Anyone happen to know what I'm doing wrong here? Thanks a bunch-
EDIT:
Wanted to mention that I'm able to connect to the database from this server using the mysql command line tools.
I installed a local mysql database, and I'm able to connect to this using isql. It seems to be ignoring my odbc.ini file entirely, i have to enter a name with the command, ie isql -v test-database, but it still tries to connect to localhost despite my settings.
I feel as though I've tried everything but will keep at it and will post if i find a solution.
You could try to connect using the ip of your server instead of the dns entry on the "Server" line of odbc.ini.. Have you verified the driver is installed with phpinfo()?
Try to set the environment variable ODBCINI with the path of your odbc.ini file.
Keep in mind that the odbc.ini file you point to must be "write-accessible" by the user that is running the program (i.e. the user must have permissions to write in this file).
chmod g+w .odbc.ini did it for me since we run the DB with ORACLE-Start and the crs-User seems to be in charge
I installed SQL Server 2012 Express and I'm learning from a book on SQL Server administration. My task is to write a batch file to copy data from a table and export it to an Excel spreadsheet.
I've got the instance name right and my username but log in fails because of password. When I enter Management Studio and click connect I see my username but password is blank, I successfully connect to my databases this way. How do I set a password for my account? I think I can't log in using SQLCMD because I don't have this set. My username is the same as my windows username, using the password that I log on to windows with doesn't work.
SQLCMD -S CRAIG-PC\SQLExpress -U CRAIG-PC\Craig -P *********
-d AdventureWorks
-Q "SELECT * FROM Sales.SalesOrderDetail" -o C:\ExportDir\export.csv
This is the command in the batch file that I'm trying to connect and query the database. If I take out -P ******* SQL Server is waiting for a password. If I don't use a username or password connection is refused.
Remote connections are enabled using tcp, but this is a local install.
Use the '-E' switch to make your connection a trusted (Window's authentication) one, then you don't need user name and password at all (provided you have sufficient rights on your machine)
http://technet.microsoft.com/en-us/library/ms162773.aspx
Note in my python code below, I don't implement the user or password.
Hope that helps
_query = "CREATE DATABASE %s ON (FILENAME = '%s'), (FILENAME = '%s') FOR ATTACH;" %(_database, mdffilepath, logfilepath)
command_process = SubP.Popen(['sqlcmd','-b', '-E',
'-S', _server,
'-d', 'master',
'-q', _query],
stdin = SubP.PIPE,
stdout = SubP.PIPE,
stderr = SubP.STDOUT,
shell = True)
_stdOut, _stdError = command_process.communicate()
Check the name of the database, ie "AdventureWorks" should be "AdventureWorks2012"
sounds like you are using windows authentication you can remove the -u and -p. when those are not provided sqlcmd will use windows authentication.