Saturday, August 8, 2020

Connect to Oracle database using command line on Ubuntu 16.04

1. Download Oracle client package (instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip) and sqlplus commandline client package (instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip) from here
Your may have latest versions, download them.

2. Now run commands
mkdir -p /opt/oracle
cd /opt/oracle

3. Unzip downloaded package instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip
unzip instantclient-basiclite-linux.x64-19.8.0.0.0dbru.zip
and move folder instantclient_19_8 in /opt/oracle

4. Install libaio package
sudo apt install libaio-dev
5. Run Commands
sudo sh -c "echo /opt/oracle/instantclient_19_8 > /etc/ld.so.conf.d/oracle-instantclient.conf"
  
sudo ldconfig

or
export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_8:$LD_LIBRARY_PATH
6. Unzip downloaded package instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
unzip instantclient-sqlplus-linux.x64-19.8.0.0.0dbru.zip
Copy all .so files of these extracted zip into /opt/oracle/instantclient_19_8
mv *.so /opt/oracle/instantclient_19_8
7. Now connect to oracle db on command line.
./sqlplus username/password@domain:port/service_name
Example :
./sqlplus root/strongpassword@54.24.xxx.xxx:1532/ORCAD
8. After connect to sql prompt, list all databases using query
select * from v$database;
Query to view the schema name by
select * from dba_users;
To display the columns available in the Oracle view v$database, we can execute the below statement.
desc v$database;

Error : pip OSError: mysql_config not found

While installing mysqlclient package from pip, you may get above error.

Package name could be like this in requirements.txt.

mysqlclient @ git+https://github.com/PyMySQL/mysqlclient-python.git@ca630c01fb39f252a4c91a525e440beea4ac4447

Solution :

sudo apt-get install libmysqlclient-dev
For recent versions of debian/ubuntu (as of 2018) it is
sudo apt install default-libmysqlclient-dev

Access denied; you need (at least one of) the SUPER or SET_USER_ID privilege(s)

While importing mysql database if you get the above error, it means the Definer is not same as the user which you are using to import the database.

If Definer is set as root in you sql file, either import the database using root user or you need to change the Definer in sql file with the username which you are using to import database.

You can find a line like this in your sql file

DEFINER = 'root'@'%'
or
DEFINER = 'root'@'localhost'

or

DEFINER = 'root'@'your-mysql-hostname'

You need to change root with your mysql user.

List all active virtualhosts of apache in Linux

If you want to list all virtualhosts of apache in Linux, here is the command

sudo apache2ctl -S

It will list all the active virtualhosts with port number. You can track easily which hosts are running on port 80 and which hosts are ssl enabled and running on port 443. 

It shows the confguration file path with name of the virtualhost, it helps user to do the required modifications.

`apache2ctl -S` is better than a2query command as it finds all the active virtualhosts in all apache config files whether it is sites-enabled or some other files.

If a virtualhost is hidden in the non-default config files, it can be easily found using above command.

Now how can you hide a apache virtualhost ?

Apache config files have preferences. If a virtual host is created in sites-enabled config file and same virtualhost with same ServerName but different DocumentRoot is created in mods-enabled config file, mods-enabled config file virtualhost will be activated as mods-enabled config file has higher preference over sites-enabled config file because its Includeoptional entry appears first in the file apache2.conf.

So if you create a virtualhost in the file /usr/src/core/base.conf and include this file at the end in the file /etc/apache2/mods-enabled/proxy.conf

IncludeOptional ../../usr/src/core/*.conf

and same virtualhost with same ServerName but different DocumentRoot is created in regular virtualhost file sites-enabled/000-default.conf, it will be hard to detect the actual virtualhost conf file location and DocumentRoot path of the project without using command `apache2ctl -S`

This was just one example, it can be created in more complex way to hide the virtualhosts and project directory path to show you the wrong application directory. It may amaze you why your project changes are not reflected or while taking backup, you can take backup of wrong directory if you are not careful enough.

That's why you should be updated with all apache tricks so no one can fool you while handing over the project.