Connect to remote MySQL server via SSH tunnel

To connect to remote MySQL server via SSH tunnel run commands:

# ssh -L 3307:1.2.3.4:3306 taras@1.2.3.4

Where 3307 local port, 1.2.3.4 remote MySQL server IP, 3306 remote MySQL port, taras – valid SSH user name.

To check if tunnel connection has been set up:

# lsof -i :3307

Connect to remove MySQL server using local SSH tunnel:

# mysql --port 3307 -h 127.0.0.1 -u db_user -p db_name

Debian 7 IPTables set up

To set up persistent IPTables rules on Debian GNU/Linux 7 (wheezy)
install package using command:

# apt-get install iptables-persistent

Save current IPTables rules using command:

# /etc/init.d/iptables-persistent save

Edit /etc/iptables/rules.v4 file for IPv4 and
/etc/iptables/rules.v6 for IPv6 rules.

To apply new rules run command:

# /etc/init.d/iptables-persistent reload

Loading iptables rules… IPv4… IPv6…done.

To view current IPTables rules:

# iptables -vnL --line-numbers |more

Git edit remote origin URL

To edit remote origin URL in Git configuration file can be edited:

# more /home/taras/.git/config

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote “origin”]
url = ssh://git@bitbucket.org/podlom/example.git
fetch = +refs/heads/*:refs/remotes/origin/*

#

Where url = ssh://git@bitbucket.org/podlom/example.git new example path.

To check new settings use command:

# git remote -v

origin ssh://git@bitbucket.org/podlom/example.git (fetch)
origin ssh://git@bitbucket.org/podlom/example.git (push)

#

Create second MySQL database and give privileges to one user

To create second MySQL database and give privileges to the same user the following commands can be used:

# mysql -h localhost -u root -p
mysql> SHOW CREATE DATABASE `database_name`;
mysql> CREATE DATABASE `database_name2` /*!40100 DEFAULT CHARACTER SET utf8 */;
mysql> SHOW GRANTS FOR database_user;
mysql> GRANT ALL PRIVILEGES ON `database\_name2`.* TO 'database_user'@'%';
mysql> FLUSH PRIVILEGES;
mysql> SHOW GRANTS FOR database_user;
mysql> quit;

SHOW CREATE DATABASE `database_name`; will show first MySQL create database DDL SQL query.

CREATE DATABASE `database_name2` /*!40100 DEFAULT CHARACTER SET utf8 */; will create second MySQL database.

SHOW GRANTS FOR database_user; is used to view current user grants.

GRANT ALL PRIVILEGES ON `database\_name2`.* TO ‘database_user’@’%’; grant all privileges to newly created database;

FLUSH PRIVILEGES; will apply new user privileges.

SHOW GRANTS FOR database_user; is used to view updated user privileges;

quit; to exit MySQL client program.

Connect to remote host via ssh proxy

To connect to remote server via ssh proxy use can use the following sequence of commands:

# lsof -i :2222
# ssh -f proxy_user@proxy_host -L 2222:destination_host:22 -N
# ssh -p 2222 destination_user@localhost

If TCP port 2222 is free you will not see any output. So you can use it for SSH proxied connection.

proxy_user – SSH user on SSH proxy server proxy_host.

destination_host – IP or host name of remote server where should we connect using proxy_host server as SSH proxy.

destination_user – SSH user on destination_host server.

apachectl – web server Apache control interface

To view possible options of apachectl – web server Apache server control interface run command:

root@shkodenko:~# apachectl --help
Usage: /usr/sbin/apachectl start|stop|restart|graceful|graceful-stop|configtest|status|fullstatus|help
       /usr/sbin/apachectl <apache2 args>
       /usr/sbin/apachectl -h            (for help on <apache2 args>)
root@shkodenko:~#

To view full version information run:

root@shkodenko:~# apachectl -V
Server version: Apache/2.2.22 (Debian)
Server built:   Feb  1 2014 21:26:04
Server's Module Magic Number: 20051115:30
Server loaded:  APR 1.4.6, APR-Util 1.4.1
Compiled using: APR 1.4.6, APR-Util 1.4.1
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/apache2/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"
root@shkodenko:~#

To view list of compiled-in modules execute:

root@shkodenko:~# apachectl -l
Compiled in modules:
  core.c
  mod_log_config.c
  mod_logio.c
  mod_version.c
  prefork.c
  http_core.c
  mod_so.c
root@shkodenko:~#

To check web server Apache syntax run:

root@shkodenko:~# apachectl configtest
Syntax OK
root@shkodenko:~#

To restart web server Apache gracefully run command:

root@shkodenko:~# apachectl graceful

List files and folders inside Java jar archive

To list files and folders inside Java jar archive use unzip.

Look at example below:

# unzip -l /home/taras/Downloads/clientControl.jar |more
Archive:  /home/taras/Downloads/clientControl.jar
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-16-2014 12:10   META-INF/
      106  02-16-2014 12:10   META-INF/MANIFEST.MF
        0  02-16-2014 12:10   database/
        0  02-16-2014 12:10   i18n/
        0  02-16-2014 12:10   lib/
        0  02-16-2014 12:10   web/
        0  02-16-2014 12:10   web/WEB-INF/
        0  02-16-2014 12:10   web/images/
        0  02-16-2014 12:10   web/style/
     2052  02-16-2014 12:10   changelog.html
      926  02-16-2014 12:10   database/clientcontrol_db2.sql
      926  02-16-2014 12:10   database/clientcontrol_hsqldb.sql
      853  02-16-2014 12:10   database/clientcontrol_mysql.sql
      934  02-16-2014 12:10   database/clientcontrol_oracle.sql
      926  02-16-2014 12:10   database/clientcontrol_postgresql.sql
      940  02-16-2014 12:10   database/clientcontrol_sqlserver.sql
      518  02-16-2014 12:10   database/import_db2.sql
      518  02-16-2014 12:10   database/import_hsqldb.sql
      518  02-16-2014 12:10   database/import_mysql.sql
      531  02-16-2014 12:10   database/import_oracle.sql
      518  02-16-2014 12:10   database/import_postgresql.sql
      518  02-16-2014 12:10   database/import_sqlserver.sql
     9970  02-16-2014 12:10   i18n/clientcontrol_i18n.properties
    21675  02-16-2014 12:10   i18n/clientcontrol_i18n_cs_CZ.properties
    20526  02-16-2014 12:10   i18n/clientcontrol_i18n_es.properties
    18680  02-16-2014 12:10   i18n/clientcontrol_i18n_fr.properties
    20470  02-16-2014 12:10   i18n/clientcontrol_i18n_pt_BR.properties
    23402  02-16-2014 12:10   i18n/clientcontrol_i18n_zh_CN.properties
    22379  02-16-2014 12:10   lib/commons-fileupload-1.0.jar
    55527  02-16-2014 12:10   lib/plugin-clientControl-jspc.jar
    37248  02-16-2014 12:10   lib/plugin-clientControl.jar
      814  02-16-2014 12:10   logo_large.gif
      592  02-16-2014 12:10   logo_small.gif
     2074  02-16-2014 12:10   plugin.xml
     4225  02-16-2014 12:10   readme.html
      636  02-16-2014 12:10   web/WEB-INF/web-custom.xml
     3964  02-16-2014 12:10   web/WEB-INF/web.xml
     2674  02-16-2014 12:10   web/images/certificateimg_error.gif
     2673  02-16-2014 12:10   web/images/certificateimg_warning.gif
     1049  02-16-2014 12:10   web/images/client-icon_adium.gif
      552  02-16-2014 12:10   web/images/client-icon_exodus.gif
     1033  02-16-2014 12:10   web/images/client-icon_ichat.gif
      363  02-16-2014 12:10   web/images/client-icon_jbother.gif
       94  02-16-2014 12:10   web/images/client-icon_pandion.gif
      592  02-16-2014 12:10   web/images/client-icon_pidgin.gif
      687  02-16-2014 12:10   web/images/client-icon_psi.gif
      591  02-16-2014 12:10   web/images/client-icon_spark.gif
      996  02-16-2014 12:10   web/images/client-icon_trillian.gif
      546  02-16-2014 12:10   web/images/icon_error.gif
      237  02-16-2014 12:10   web/images/icon_help_14x14.gif
      415  02-16-2014 12:10   web/images/icon_warning-small.gif
      538  02-16-2014 12:10   web/images/icon_warning.gif
      645  02-16-2014 12:10   web/images/mac.gif
       51  02-16-2014 12:10   web/images/reports_selected-arrow.gif
     1015  02-16-2014 12:10   web/images/win.gif
      241  02-16-2014 12:10   web/images/zip.gif
     7006  02-16-2014 12:10   web/style/style.css
---------                     -------
   274964                     57 files

Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket

Еverything happens for the first time ever.

Today, first time I have seen such MySQL service error during start: Unable to start MySQL service. Another MySQL daemon is already running with the same UNIX socket.

First item to check: main MySQL service log /var/log/mysqld.log and main configuration file /etc/my.cnf

Then I have found nice KB article on Rackspace: http://kb.parallels.com/en/119334

It has helped me to solve this problem.

I have runned command to kill all possible running MySQL daemons:

# killall -9 mysqld_safe mysqld

And then I have made changes below to MySQL service startup script /etc/init.d/mysqld:

# cp -fv /etc/init.d/mysqld /etc/init.d/mysqld.orig
# diff -c /etc/init.d/mysqld.orig /etc/init.d/mysqld

+       # We check if there is already a process using the socket file,
+       # since otherwise this init script could report false positive
+       # result and mysqld_safe would remove the socket file, which
+       # actually uses a different daemon.
+       if fuser "$socketfile" &>/dev/null ; then
+           echo "Socket file $socketfile exists. Is another MySQL daemon already running with the same unix socket?"
+           action $"Starting $prog: " /bin/false
+           return 1
+       fi

-       if [ -S "$socketfile" ] ; then
-           echo "Another MySQL daemon already running with the same unix socket."
-           action $"Starting $prog: " /bin/false
-           return 1
-       fi

Then I have started MySQL server using command:

# /etc/init.d/mysqld start

There is another method to fix problems with MySQL server error:
Another MySQL daemon already running with the same unix socket

Run command:

# rm -fv $(grep socket /etc/my.cnf | cut -d= -f2) && /sbin/service mysqld start

Both of methods listed above has solved MySQL issues for me.