Frequently used mysql commands



Step 0: Read useful links

Step 1: Update your system by typing the following commands:

sudo apt update
sudo apt upgrade

Step 2: Install mysql version 5.7 on Ubuntu 16.04

sudo apt install mysql-server mysql-client

Step 3: Run mysql_secure_installation to secure your installation

sudo mysql_secure_installation

Step 4: How do I use MySQL server?

$ mysql -u root -p

Step 5: How do I create a new MySQL server database and user account?

CREATE DATABASE mydatabase CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Grant privileges for user on database.table

GRANT [тип прав] ON [database's name].[table's name] TO [username]@'localhost;

Show user in MySQL:

mysql> select * from mysql.user;


mysql> select host, user, password from mysql.user;

Remove rights for user

REVOKE [тип прав] ON [database's name].[table's name FROM [username]@localhost;

Remove database from mysql server

DROP USER demo@localhost;

How to change password for some user in MySQL

SET PASSWORD = PASSWORD('passwordphrase')

Password for some user can be changed by this commands:

SET PASSWORD FOR username@localhost = PASSWORD('passwordphrase');
SET PASSWORD FOR username@"%" = PASSWORD('passwordphrase');

The same is can be done by these commands:

UPDATE mysql.user SET Password=PASSWORD('passwordphrase') WHERE User='логин' AND Host='localhost';


GRANT USAGE ON БД.* TO username@localhost IDENTIFIED BY 'passwordphrase';


mysqladmin -u username password passwordphrase

How to Install SSH2 extension for PHP on Centos


yum install gcc php-devel php-pear libssh2 libssh2-devel make
pecl install -f ssh2
echo > /etc/php.d/ssh2.ini
service httpd restart
php -m | grep ssh2 

script that running unicorn for redmine


/usr/bin/perl /root/scripts/

#! /usr/bin/perl -w
use strict;
use warnings;

print "running helpdesk\n";
print $ENV{'PATH'};
system ("BUNDLE_GEMFILE=/var/www/html/redmine/Gemfile bundle exec unicorn_rails -E production -c /var/www/html/redmine/config/unicorn.rb -D");

nginx as revers proxy

upstream redmine {
    server unix:/var/www/html/redmine/tmp/sockets/unicorn.sock;

     server {
         listen 80;
         client_max_body_size 200m;
         root /var/www/html/redmine/;

      location / {
          try_files $uri @ruby;

       location ~* \.(jpg|gif|png|js|css|ico)$ {
               root /var/www/html/redmine/public;
               expires 7d;
               error_page 404 502 504 = @ruby;

        location @ruby {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  Host $http_host;
        proxy_redirect off;
        proxy_read_timeout 300;
        proxy_pass http://redmine; #upstream redmine

GitHub – denisgolius