I successfully installed the offical MSSQL ODBC drivers in Linux and I can connect to every database and execute commands with isql:
sudo isql -v dsn user pw
However, if I execute a SQL statement (select ...) in my own application it is not possible to fetch data ("Driver does not support this function") -> I think it is because isql needs sudo rights.
Is there any way to execute isql without sudo?
I tried to change (chmod, chown) some rights for isql, but I still need sudo.
I found the solution. The problem was not isql, but the location of odbc.ini and odbcinst.ini!
As "sudo" the connection is looking at /etc/odbc.ini and /etc/odbcinst.ini
As "normal" user the connection is looking at a path like that: /usr/local/odbc.ini and /usr/local/odbcinst.ini
I edited both files and the connection worked!
this should not be the case. Can you try a SELECT ##Version? Alternatively, can you try running the same query via sqlcmd?
Steps to install and run sqlcmd are here: https://blogs.msdn.microsoft.com/sqlnativeclient/
Related
I installed oracle db version 12c in my docker environment.
I used the following command:
docker run -d --name oracle -p 8080:8080 -p 1521:1521 quay.io/maksymbilenko/oracle-12c
I connected to the DB and everything went well but I wanted to enable unified audit.
In order to do that, at first you must shutdown the Database and in all the instructions that I found it says to use sqlplus as following:
sqlplus / as sysoper
SQL> shutdown immediate
SQL> exit
I connected successfully to the DB using the next command:
docker exec -it oracle "bash"
and then I ran the sqlplus command and I received "command not found"
[root#f30cc670f85f /]# sqlplus / as sysoper
bash: sqlplus: command not found
Am I doing it wrong?
What should I do in order to have sqlplus on my oracle DB?
I looked for it and didn't find anything that helped me.
I have mac if its relevant
I think that Docker image is just the database and enough of the OS to run the database. I don't think it includes client software such as SQL*Plus.
You need to have SQL*Plus installed on your Mac. If you haven't already, download the Oracle Instant Client for MacOS including the SQL*Plus extension. Or why not treat yourself and install the new-fangled sqlCL tool? It is easier to install and has all the SQL*Plus capabilities and a whole bunch more features. Find it here.
Whatever client you choose, once it's installed on your Mac you run it like any other app: when prompted for connection you give the string Maksym provides:
system/oracle#//localhost:1521/xe
If you need to connect as sys that would look like this:
sys/oracle#//localhost:1521/xe as sysdba
Sourcing the .bashrc should work to connect to sqlplus as sysdba.
docker-compose exec db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1#ORCLCDB as sysdba;"
with this, you enter the image:
docker exec -it oracle /bin/bash
after that, you can use:
sqlplus sys as sysdba
When using the docker image store/oracle/database-enterprise:12.2.0.1-slim sqlplus and sqlldr tools are only available after the container has started.
You can't do the following in a Dockerfile:
RUN sqlplus sys/password AS SYSDBA #create_database.sql
The container images can be configured to run scripts after setup and on startup. Currently sh and sql extensions are supported.
In your Dockerfile, copy the SQL script into the startup directory:
COPY create_database.sql /opt/oracle/scripts/setup/01_create_database.sql
The database will be created on first startup of the container.
I don't have any experience with docker, but it looks for all the world like you are getting to a bash environment, so there we are on solid ground. The returned error ("bash: sqlplus: command not found") simply means that the executable (sqlplus) was not found in any directory listed in your PATH environment variable, as it exists within your shell environment. You actually need to set three variables: ORACLE_SID needs to be set to the value of your database name. ORACLE_HOME needs to be set to the value of the directory where your oracle binaries are installed. And PATH needs to have $ORACLE_HOME/bin added to it:
export PATH=$ORACLE_HOME/bin:$PATH
Obviously, since you are using the value of ORACLE_HOME in setting PATH, ORACLE_HOME needs to be set first.
For Windows OS:
Type docker ps in command line to show running containers and check container id.
Type docker exec -it container_id //bin/bash
Login via sqlplus command
Or the simplest way
docker exec -it container_id bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1#ORCLCDB as sysdba;"
More info is here: https://hub.docker.com/u/cgmmathaw/content/sub-90f0c051-b514-4b7b-a0fe-fc9d6f2172fa
When I want to login as 'sa' user in my mssql server by this command:
sqlcmd -S localhost -U sa
I got this error:
'Reason: Server is in script upgrade mode. Only administrator can connect at this time..'
I read about -T902 parameter, who is connected to this problem, but don't know how to start mssql server with that paramater in Ubuntu, if it's needed. I also ran mssql-conf script and choose 2) Developer option and setup a password for 'sa' user. I also use DBeaver tool. What shall I do? Thx in an advance.
System:
Ubuntu 17.10
SQL Server (latest version) - 14.0.3022.28-2
Dbeaver - 4.3.5
This one is really starting to stump me. I'm running Ubuntu 12.04 and am trying to connect to a box running MS SQL server 2012. First I'll provide some information on my setup:
My freetds.conf:
[EXNAME]
host = IP
port = 1433
tds version = 7.0
client charset = UTF-8
After setting up my freetds.conf I first test my connection with tsql which produced the expected (and welcomed) prompt:
...
using default charset "UTF-8"
1>
So my FreeTDS setup appears to be working ok. Next I setup odbc.ini and obdcinst.ini:
odbc.ini:
[EXNAME]
Driver = FreeTDS
ServerName = EXNAME
UID = Me
PWD = Pass
odbcinst.ini:
[FreeTDS]
Description = FreeTDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
Following this setup I run osql to check. It outputs all the expected responses, it is able to find the drivers and the correct paragraphs in ondcb.ini for example:
[EXNAME] found in /etc/odbc.ini
found this section:
[EXNAME]
Driver = FreeTDS
ServerName = EXNAME
UID = Me
PWD = Pass
looking for driver for DSN [EXNAME] in /etc/odbc.ini
found driver line: " Driver = FreeTDS"
And so on until:
DSN [EXNAME] has servername "" (from /etc/odbc.ini)
osql does not seem to be detecting the servername in odbc.ini.
Following this check I am able to connect via isql but I cannot run any SQL commands. I receive the following error:
SQL> SELECT name FROM master..sysdatabases;
[37000][unixODBC][FreeTDS][SQL Server]Could not find stored procedure 'SELECT'.
[ISQL]ERROR: Could not SQLExecute
What I've tried:
A.) Just about every configuration and naming convention one could think of across freetds.conf and both .ini files. Post changes I perform the same tests above and arrive at the same result
B.) Reproducing the error outside of isql. ROBC given me exactly the same error. Of course, this is expected but I figured why not
C.) SQL variants besides MS SQL Server. I figured just in case someone was mis-informing me I tried some MySQL commands there as well. This could be a SQL problem but I'm ot sure.
D.) The closest I've come to finding a similar error (well result I guess) to what osql spit out is here. As suggested in the last post, the problem, at least in so far as it relates to osql's response might relate to awk. As suggested I test awk by making a variable and trying to parse out the servername:
$ SERVER_LINE='ServerName = SERVER'
$ echo ${SERVER_LINE} | awk -F '=[[:space:]]*' '{print $2}'
This should result in SERVER but instead I get "".
That's all I have. In summary OSQL cannot seem to find the servername in odbc.ini and this may or may not result in me not being able to execute any commands from ISQL or ROBC. I'm beginning to suspect that these problems are disjoint but any help would be GREATLY appreciated.
EDIT:7/31/2014
Got this all working. There were some other issues going on in addition to what I highlighted. I ended up having to set up a similar connection on both a Mac and Linux box. Here are the instructions for both:
http://www.joecjr.com/2014/07/27/install-and-use-freetds-unixodbc-and-rodbc-or-pyodbc/
It took me a LONG time to properly configure unixODBC with TDS, but for what it's worth, this set of instructions was my saving grace and what finally allowed me to get it working:
http://www.unixodbc.org/doc/FreeTDS.html
Pay particular attention to the second that references this command:
odbcinst -i -s -f tds.datasource.template
It's where my biggest problem resided. What happened was I was doing this as root (which is fine), but if you read carefully it indicates that every user that uses the driver has to run this command to 'register' the connection for their userid. Once I ran the same command under each other user, everything worked fine (since my actual code doesn't run as root).
One other thought... a quick and easy test to see if the connection is actually working with TDS (even before you try the ODBC piece) is to run bcp and export a really small table.
Try something like this, just to rule out the TDS install being the issue.
freebcp <database>.dbo.<tablename> out $HOME/foo.out -c -t '|' \
-S <hostname>:<port> -U <userid> -P <password>
It's a shame Microsoft and Unix don't play nicer together.
I'm running through the Cloudera Manager (free edition) and I reached the point where the wizard is creating the Hive Metastore Database.
This error is shown and halts the configuration process.
using /var/run/cloudera-scm-agent/process/40-hive-metastore-create-tables/hadoop-conf as HADOOP_CONF_DIR
I cant seem to find any information that might cause this?
Every thing has been configured correctly up to this point, everything installed and user names and passwords are correct.
Has anybody seen this error before? Thoughts?
Error Log:
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:688)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1094)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2337)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2370)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2154)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.cloudera.enterprise.dbutil.SqlRunner.open(SqlRunner.java:109)
at com.cloudera.enterprise.dbutil.SqlRunner.runSingleQuery(SqlRunner.java:80)
at com.cloudera.cmf.service.hive.HiveMetastoreDbUtil.countTables(HiveMetastoreDbUtil.java:191)
... 2 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2540)
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:612)
... 20 more
ok cloudera is using version HIVE 0.10, that doesn't support remote login
but you need to go around that bug, logging to the server that is getting the error the cloudera manager will tell you the ip
1) create login in to the Server that fails to install HIVE
2) Create a $HADDOP_HOME
$HADOOP_HOME="/usr/lib/hadoop/"
3) INSTALL postgres in the server that fails
`$ sudo apt-get install postgresql`
$ cat /etc/postgresql/9.1/main/postgresql.conf | grep -e listen -e standard_conforming_strings
modify this to lines in the file
listen_addresses = '*'
standard_conforming_strings = off
You also need to configure authentication for your network in pg_hba.conf. You need to make sure that the PostgreSQL user that you will create in the next step will have access to the server from a remote host. To do this, add a new line into pg_hba.con that has the following information:
host <database> <user> <network address> <mask> password
Start PostgreSQL Server
$ sudo service postgresql start
Use chkconfig utility to ensure that your PostgreSQL server will start at a boot time:
chkconfig postgresql on
You can use the chkconfig utility to verify that PostgreSQL server will be started at boot time, for example:
chkconfig --list postgresql
Step 2: Install the Postgres JDBC Driver
Before you can run the Hive metastore with a remote PostgreSQL database, you must configure a JDBC driver to the remote PostgreSQL database, set up the initial database schema, and configure the PostgreSQL user account for the Hive user.
To install the PostgreSQL JDBC Driver on a Debian/Ubuntu system:
Install libpostgresql-jdbc-java and symbolically link the file into the /usr/lib/hive/lib/ directory.
$ sudo apt-get install libpostgresql-jdbc-java
$ ln -s /usr/share/java/postgresql-jdbc4.jar /usr/lib/hive/lib/postgresql-jdbc4.jar
Step 3: Create the metastore database and user account
bash# sudo –u postgres psql
bash$ psql
postgres=# CREATE USER hiveuser WITH PASSWORD 'mypassword';
postgres=# CREATE DATABASE metastore;
postgres=# \c metastore;
You are now connected to database 'metastore'.
postgres=# \i /usr/lib/hive/scripts/metastore/upgrade/postgres/hive-schema-0.10.0.postgres.sql
SET
SET
...
Now you need to grant permission for all metastore tables to user hiveuser. PostgreSQL does not have statements to grant the permissions for all tables at once; you'll need to grant the permissions one table at a time. You could automate the task with the following SQL script:
bash# sudo –u postgres psql
metastore=# \o /tmp/grant-privs
metastore=# SELECT 'GRANT SELECT,INSERT,UPDATE,DELETE ON "' || schemaname || '"."' || tablename || '" TO hiveuser ;'
metastore-# FROM pg_tables
metastore-# WHERE tableowner = CURRENT_USER and schemaname = 'public';
metastore=# \o
metastore=# \i /tmp/grant-privs
You can verify the connection from the machine where you'll be running the metastore service as follows:
psql –h myhost –U hiveuser –d metastore
metastore=#
Step 4: Configure the Metastore Service to Communicate with the PostgreSQL Database
change the IP of the AWS amazon master Server, or your master server, don't use DNS name
$find / -name hive-site.xml
$nano /run/cloudera-scm-agent/process/27-hive-metastore-create-tables/hive-site.xml
in the File search for:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:postgresql://myhost/metastore</value>
</property>
and change to the correct IP that is your Master Hadoop Server where u are running Cloudera Manager
also every link in that file that is not correctly write to the hadoop master Cloudera manager connector , you will have to change to the correct IP
after all this just get back to the autoinstall of cloudera manager and run again and it will be all good :)
that it all the installation that you have to work around our contract cloudera support (that's their business) :)
all this it works fine for me when i have this problem in de cloudera CDH 4.X with sorl
Regards
Go to this link :
http://www.cloudera.com/documentation/enterprise/5-7-x/topics/cm_ig_mysql.html
Go to this topic: Installing the MySQL JDBC Driver
Follow the instruction. Finally Restart your hive service
Thx Kumar
I want to use the pre-installed postgresql on my local machine (mac os 10.7.5), when I run which psql I find it (in /usr/bin/psql), but then running
pg_ctl -D /usr/bin/psql -l /usr/bin/psql/server.log start
results in:
-bash: pg_ctl: command not found
How can I start/use my postgresql database? do I need to install it (with say Homebrew) or can I use the pre-installed one on my mac?
I also tried using the initdb command (initdb /usr/bin/psql -E utf8) and also go tthe same message: -bash: initdb: command not found.
Also, is this psql the same as postgres? (I tried which postgres and got nothing)
Update: I'm using psql commands in the command line, but am getting there the following message (for psql -l and psql -a for instance):
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
OS X ships with the command line client (for interacting with postgres databases) not the server.
You need to install the server.
Check the postgres site or grab the postgres.app