Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

Speed up scp file transfer

Speed up scp file transfer

Speed up scp file transfer
20/05/2008
Syed Atif Ali Whats the fastest encryption to transfer files with SCP ?

Description :
Many times it is required to transfer files across machines on the same network , all machinesbeing on the same network and behind proxy its useless to transfer them with an encryptionwhich is more CPU ntensive than other and also slower than others.There can be other methods to transfer files of course , ftp , sftp , rsync, but this document is justabout scp command.

Objective :
To find out what is the faster cypher to define in scp command to transfer files on an internallocal network.

Environment :
Two Linux machines, with same openssh versions.Connected on a 100 Mbps LAN . Both being idle nothing is running on them at the moment .Before each test files will be cached on the file system buffer , so the tests are not affected withcache.
Tests :
Copy 1000 small, medium , large files across the network using different cyphers in scp command and measure their real time.

These are the file sizes :
Small : 10K
Medium: 100K
Large:1000K

Overall arcfour performed better than any other cypher used. It is safe to say that arcfour
can beused to transfer files using scp on an internal network.

You can define which cypher to use by -c option of scp.

scp -c arcfour filename.txt host:/path/filename

/etc/ssh/ssh_config
Ciphers arcfour128,arcfour256,arcfour,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc

[CentOS 7.0] Change network interface name (eno* to eth0)

[CentOS 7.0] Change network interface name (eno* to eth0)

Step1)
# vim /etc/udev/rules.d/70-persistent-net.rules
———————————————————————–
# PCI device 0x14e4:0x1680 (tg3)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:0c:29:7b:d8:06“, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eno16777736“, NAME=”eth0
———————————————————————–
or
———————————————————————–
# PCI device 0x14e4:0x1680 (tg3)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:0c:29:7b:d8:06“, ATTR{dev_id}==”0x0″, ATTR{type}==”1″, KERNEL==”eno*“, NAME=”eth0
———————————————————————–
Step2)
# mv /etc/sysconfig/network-scripts/ifcfg-eno16777736 /etc/sysconfig/network-scripts/ifcfg-eth0

Step3)
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
———————————————————————–
HWADDR=”00:0C:29:7B:D8:06″
TYPE=”Ethernet”
BOOTPROTO=”dhcp”
DEFROUTE=”yes”
PEERDNS=”yes”
PEERROUTES=”yes”
IPV4_FAILURE_FATAL=”no”
IPV6INIT=”yes”
IPV6_AUTOCONF=”yes”
IPV6_DEFROUTE=”yes”
IPV6_PEERDNS=”yes”
IPV6_PEERROUTES=”yes”
IPV6_FAILURE_FATAL=”no”
NAME=”eth0″
UUID=”2aa76b48-487b-425e-a021-ace79c0773cd”
ONBOOT=”yes”
———————————————————————–

Step4)
# reboot

[CentOS 7.0] Change the default “enxx” network device to old “eth0” on CentOS 7

[CentOS 7.0] Change the default “enxx” network device to old “eth0” on CentOS 7

The easiest way to restore the old way Kernel/modules/udev rename your ethernet interfaces is supplying these kernel parameters to CentOS 7:

net.ifnames=0
biosdevname=0

To do so follow this steps:

Edit /etc/default/grub
At the end of GRUB_CMDLINE_LINUX line append “net.ifnames=0 biosdevname=0”
Save the file
Type “grub2-mkconfig -o /boot/grub2/grub.cfg”
Type “reboot”

If you didn’t supply these parameters during the installation, you will probably need to adjust and/or rename interface files at /etc/sysconfig/network-scripts/ifcfg-*.

Up to Fedora 18, just biosdevname=0 was enough.

As an example, in a certain machine, in a exhaustive research, I got:

-No parameters: NIC identified as “enp5s2”.
-Parameter biosdevname=0: NIC identified as “enp5s2”.
-Parameter net.ifnames=0: NIC identified as “em1”.
-Parameter net.ifnames=0 AND biosdevname=0: NIC identified as “eth0”.

[CentOS 7.0] Configure Networking

[CentOS 7.0] Configure Networking

[1] Set static IP address to the server. ( Replace the section ‘ifcfg-***’ to your own interface name )

# install the package below which includes ifconfig, netstat and so on first

[root@dlp ~]#yum -y install net-tools

[root@dlp ~]#vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

HWADDR=”00:0C:29:CD:9C:2D”
TYPE=”Ethernet”

# change
BOOTPROTO=”none”
DEFROUTE=”yes”
PEERDNS=”yes”
PEERROUTES=”yes”
IPV4_FAILURE_FATAL=”no”
IPV6INIT=”yes”
IPV6_AUTOCONF=”yes”
IPV6_DEFROUTE=”yes”
IPV6_PEERDNS=”yes”
IPV6_PEERROUTES=”yes”
IPV6_FAILURE_FATAL=”no”
NAME=”eno16777736″
UUID=”3eb052b5-f8f2-4609-b70b-e44a050f6524″
ONBOOT=”yes”
# add like follows
# this server’s IP address
IPADDR=”10.0.0.30″

# subnet mask
NETMASK=”255.255.255.0″

# default gateway
GATEWAY=”10.0.0.1″

# DNS server’s IP address
DNS1=”10.0.0.1″

[root@dlp ~]#systemctl stop NetworkManager

[root@dlp ~]#systemctl disable NetworkManager

rm ‘/etc/systemd/system/multi-user.target.wants/NetworkManager.service’
rm ‘/etc/systemd/system/dbus-org.freedesktop.NetworkManager.service’
rm ‘/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service’

[root@dlp ~]#systemctl restart network

[root@dlp ~]#chkconfig network on

[root@dlp ~]#ifconfig

eno16777736: flags=4163  mtu 1500
inet 10.0.0.30  netmask 255.255.255.0  broadcast 10.0.0.255
inet6 fe80::20c:29ff:fecd:9c2d  prefixlen 64  scopeid 0x20
ether 00:0c:29:cd:9c:2d  txqueuelen 1000  (Ethernet)
RX packets 5978  bytes 7634267 (7.2 MiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 3256  bytes 287222 (280.4 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
inet 127.0.0.1  netmask 255.0.0.0
inet6 ::1  prefixlen 128  scopeid 0x10
loop  txqueuelen 0  (Local Loopback)
RX packets 0  bytes 0 (0.0 B)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 0  bytes 0 (0.0 B)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[2] Disable IPv6 if you do not need it.

[root@dlp ~]#vi /etc/default/grub

# line 6: add
GRUB_CMDLINE_LINUX=”ipv6.disable=1 rd.lvm.lv=fedora/swap rd.md=0…..

# reload
[root@dlp ~]#grub2-mkconfig -o /boot/grub2/grub.cfg

[root@dlp ~]#reboot

[3] if you’d like to use the network interface name as ethX, configure like follows.

[root@dlp ~]#vi /etc/default/grub

# line 6: add
GRUB_CMDLINE_LINUX=”net.ifnames=0 rd.lvm.lv=fedora/swap rd.md=0…..

# reload
[root@dlp ~]#grub2-mkconfig -o /boot/grub2/grub.cfg

[root@dlp ~]#reboot

[CentOS 7.0] Change RunLevel

[CentOS 7.0] Change RunLevel

[1] RunLevel is set with linking to /etc/systemd/system/default.target. For example, the default setting without GUI is like follows.

# show current setting
[root@dlp ~]#systemctl get-default
multi-user.target

[root@dlp ~]#ll /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 37 Jul 9 06:04 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target

[2] For example, if you’d like to change the RunLevel to Graphical-login, set like follows.

[root@dlp ~]#systemctl set-default graphical.target
rm ‘/etc/systemd/system/default.target’
ln -s ‘/usr/lib/systemd/system/graphical.target’ ‘/etc/systemd/system/default.target’

# make sute the setting
[root@dlp ~]#systemctl get-default
graphical.target

[root@dlp ~]#ll /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 36 Jul 9 21:55 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target

[CentOS 7.0] Configure Services

[CentOS 7.0] Configure Services

[1] Configure Services of the System.

# list services which are booted (list all includes inactive one with “–all” option)

[root@dlp ~]#systemctl -t service

UNIT                                    LOAD   ACTIVE SUB     DESCRIPTION
auditd.service                      loaded active running Security Auditing Service
avahi-daemon.service         loaded active running Avahi mDNS/DNS-SD Stack
crond.service                       loaded active running Command Scheduler
dbus.service                        loaded active running D-Bus System Message Bus
getty@tty1.service               loaded active running Getty on tty1



systemd-udevd.service                   loaded active running udev Kernel Device Manager
systemd-update-utmp.service             loaded active exited  Update UTMP about System Reboot/Shutdown
systemd-user-sessions.service           loaded active exited  Permit User Sessions
systemd-vconsole-setup.service          loaded active exited  Setup Virtual Console
tuned.service                           loaded active running Dynamic System Tuning Daemon

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

37 loaded units listed. Pass –all to see loaded but inactive units, too.
To show all installed unit files use ‘systemctl list-unit-files’.

# list boot config of services
[root@dlp ~]#systemctl list-unit-files -t service

UNIT FILE                              STATE
arp-ethers.service                     disabled
auditd.service                         enabled
autovt@.service                        disabled
avahi-daemon.service                   enabled
blk-availability.service               disabled



systemd-user-sessions.service          static
systemd-vconsole-setup.service         static
teamd@.service                         static
tuned.service                          enabled
wpa_supplicant.service                 disabled

124 unit files listed.

[2] Stop and turn OFF auto-start setting for a service if you don’d need it. (it’s postfix as an example below)

[root@dlp ~]#systemctl stop postfix

[root@dlp ~]#systemctl disable postfix
rm ‘/etc/systemd/system/multi-user.target.wants/postfix.service’

[3] There are some SysV services yet. Those are controled by chkconfig like below.

[root@dlp ~]#chkconfig –list

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use ‘systemctl list-unit-files’.
To see services enabled on particular target use
‘systemctl list-dependencies [target]’.

iprdump         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprinit         0:off   1:off   2:on    3:on    4:on    5:on    6:off
iprupdate       0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

# for exmaple, turn OFF auto-start for netconsole

[root@dlp ~]#chkconfig netconsole off

MySQL : interactive_timeout v/s wait_timeout

MySQL : interactive_timeout v/s wait_timeout

Most of the database intensive applications are working about the default values of these variables obviously. Developers used to inform me that they need to extend the wait_timeout value in order to complete the query execution.

After some googling, it is found that default “wait_timeout” value is good enough. We may need to reduce it to boost the server performance which will helpful to minimize the “sleep” process loaded in memory. Increasing number of sleeping process will reduces the server performance gradually. So always keep the default value and make it reduce until the program/application does not create any sleeping process which would helpful to improve the performance noticeable. Slow_log_query is another possible reason to have many sleeping process.

interactive_timeout : interactive time out for mysql shell sessions in seconds like mysqldump or mysql command line tools.
wait_timeout” : the amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection in seconds.

How to change the these variables

a. changing values at run time
Log in to the mysql console and set the variable.
mysql> SET interactive_timeout=200;
Query OK, 0 rows affected (0.01 sec)

mysql> SET GLOBAL interactive_timeout=200;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like "%timeout%";
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| connect_timeout | 200 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 200 |
| net_read_timeout | 200 |
| net_write_timeout | 200 |
| slave_net_timeout | 3600 |
| table_lock_wait_timeout | 50 |
| wait_timeout | 200 |
+----------------------------+-------+
10 rows in set (0.00 sec)

b. Using my.cnf : Add the following values in /etc/my.cnf” and restart the mysql server.
[mysqld]
interactive_timeout=180
wait_timeout=180

Pls note that “wait_timeout” would be helpful to clear the sleeping process as “interactive_timeout” does not make any performance improvement since it affect the command line sessions. Obviously increasing the values of connect_timeout,net_read_timeout and net_write_timeout would help to skip the timeout errors when lengthy queries are being executed.

How to kill the MySQL Sleeping process

mysql> show full processlist;
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| 9435 | user | 192.168.10.15:52180 | db1 | Sleep | 26 | | NULL |
| 9943 | user | localhost:51179 | db2 | Sleep | 1 | | NULL |
| 9944 | user | localhost:54007 | db2 | Sleep | 29 | | NULL |
| 9947 | user | localhost:60638 | db2 | Sleep | 29 | | NULL |
| 10716 | root | localhost | NULL | Sleep | 5432 | | NULL |
| 10851 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
6 rows in set (0.00 sec)

mysql> kill 9944;
Query OK, 0 rows affected (0.00 sec)

mysql> show full processlist;
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| 9435 | user | 192.168.10.15:52180 | db1 | Sleep | 7 | | NULL |
| 9943 | user | localhost:51179 | db2 | Sleep | 9 | | NULL |
| 9947 | user | localhost:60638 | db2 | Sleep | 10 | | NULL |
| 10716 | root | localhost | NULL | Sleep | 5473 | | NULL |
| 10851 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
| +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
7 rows in set (0.01 sec)
mysql>

How and Why You Should Change MySQL’s wait_timeout and interactive_timeout Variables

How and Why You Should Change MySQL’s wait_timeout and interactive_timeout Variables

wait_timeout variable represents the amount of time that MySQL will wait before killing an idle connection.
The default wait_timeout variable is 28800 seconds, which is 8 hours. That’s a lot.

I’ve read in different forums/blogs that putting wait_timeout too low (e.g. 30, 60, 90) can result in MySQL has gone away error messages.
So you’ll have to decide for your configuration.

Requirement: You will need admin/root access to the server.

Step 1) Edit your /etc/my.cnf file and enter the following 2 values.

[mysqld]
interactive_timeout=300
wait_timeout=300

Step 2) run the command and enter your root password
mysql -uroot -p -e”SET GLOBAL wait_timeout=300; SET GLOBAL interactive_timeout=300;”

If you are connected from the mysql console
e.g. mysql> you can run this command which will show you global and session variables.

SELECT @@global.wait_timeout, @@global.interactive_timeout, @@session.wait_timeout, @@session.interactive_timeout;

+———————–+——————————+————————+——————————-+
| @@global.wait_timeout | @@global.interactive_timeout | @@session.wait_timeout | @@session.interactive_timeout |
+———————–+——————————+————————+——————————-+
|                   300 |                          300 |                  28800 |                         28800 |
+———————–+——————————+————————+——————————-+
1 row in set (0.00 sec)

To see the the current values you can run this command
mysql> show global variables like ‘%timeout%’;

+—————————-+———-+
| Variable_name              | Value    |
+—————————-+———-+
| connect_timeout            | 10       |
| delayed_insert_timeout     | 300      |
| innodb_lock_wait_timeout   | 50       |
| innodb_rollback_on_timeout | OFF      |
| interactive_timeout        | 300      |
| lock_wait_timeout          | 31536000 |
| net_read_timeout           | 30       |
| net_write_timeout          | 60       |
| slave_net_timeout          | 3600     |
| wait_timeout               | 300      |
+—————————-+———-+
10 rows in set (0.00 sec)

Credits:
Step1 instructions from RolandoMySQLDBA
http://serverfault.com/questions/355750/mysql-lowering-wait-timeout-value-to-lower-number-of-open-connections

Step 2) Eliot Kristan’s blog http://www.eliotk.net/12/21/mysql-wait_timeout-default-is-set-too-high/

Detailed MySQL basic commands

Detailed MySQL basic commands

Format: mysql -h host address -u user name -p User password

1, is connected to the machine on MYSQL.
First, open a DOS window, then enter the directory mysql \ bin, then type the command mysql -u root -p, you lose the password prompt after the carriage return may or may not have a space before the space Note that the user name, but there must be no space before the password, or let re-enter your password.

If you have just installed MYSQL, super-user root no password, so you can directly enter into the MYSQL, MYSQL prompt is: MySQL>

2, to connect to remote host on MYSQL. Suppose the remote host IP is: 110.110.110.110, user name is root, password is abcd123. Type the following command:
MySQL -h110.110.110.110 -u root -p 123; (Note: You can not add a space between u and the root, the other is the same)

3, exit MYSQL command : exit (Enter)

 

2. Change Password

Format: mysqladmin -u username -p password old password new password

1, to add a root password ab12.
First, enter the DOS directory mysql \ bin, then type the following command
mysqladmin -u root -password ab12
Note: Since the beginning of root without a password, so the -p an old password can be omitted.

2, then the root password to djg345.
mysqladmin -u root -p ab12 password djg345
3, add new users

Note: different above and below the MYSQL environment because it is a command, so the back with a semicolon as a command terminator

format:. Grant select on database * to username @ log on the host identified by “password”

1, adding a password for the user test1 abc, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First, the root user connected to MYSQL, and then type the following command:
Grant SELECT, INSERT, Update, the Delete ON * * to [Email = test1 @ “%] test1 @”% [/ Email] “Identified by” ABC “;.

But increase in users is very dangerous, you want to know as someone test1 password, then he can log your mysql database and the data you can do whatever the solution, see 2 on the internet on any computer.

2, add a user test2 password is abc, so that he can only log on localhost, and can query the database mydb, insert, modify, delete operations (localhost means the local host, that is, MYSQL database where that host) , so that users know that the use test2 password, he can not directly access the database from the internet, can only be accessed through the web page MYSQL host.
Grant SELECT, INSERT, Update, the Delete oN mydb. * to [Email = test2 @ localhost] test2 @ localhost [/ email ] identified by “abc”;

If you do not want test2 password, you can resort to a command to eliminate the password.
Grant SELECT, INSERT, Update, the Delete mydb ON * to [@ Email = test2. localhost] test2 @ localhost [/ email ] identified by “”;

4.1 Creating a database

Note: Creating a first connection Mysql database server before

the command: create database <database name>

Example 1: Create a database called xhkdb the
mysql> create database xhkdb;

Example 2: Creating a database and assigned a user

?CREATE DATABASE database name;

?GRANT the SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON * TO database name, database name @localhost IDENTIFIED BY ‘password’;.

?SET the FOR pASSWORD ‘database name’ @ ‘localhost’ = OLD_PASSWORD ( ‘ password’);

followed by the implementation 3 command to create a complete database. Note: Chinese “Password” and “database” is the need to set up their own households.
4.2 Displaying Database

Command: show databases (Note: There is a final S)
MySQL> Show Databases;

Note: For longer garbled when displayed, to modify the database default encoding. In the following pages GBK encoding as an example:

1, MYSQL modify configuration files: the my.ini modify inside-Character-SET = default GBK
2, run-time code modification:
?Java Code: jdbc: mysql: // localhost: 3306 / ? the Test useUnicode = to true & characterEncoding = GBK
?PHP Code: header ( “the Content-the Type: text / HTML; charset = GB2312”);
? C language code: int mysql_set_character_set (MYSQL * mysql, char * csname);
this function is used for the current connection set the default character set. Csname string specifies a valid character set name. Connection collation becomes the default collation character set. The function of the statement of work is similar to SET NAMES, but it can also set mysql-> charset value, thus affecting the set by mysql_real_escape_string () character set.

 
4.3 Delete Database

Command: drop database <database name>
For example: to delete a database named xhkdb
mysql> drop database xhkdb;

Example 1: Delete an already existing database to determine the
MySQL> the drop DROP DATABASE Database;
Query the OK, 0 rows affected (0.00 sec)

Example 2 : delete an uncertain existence of the database
MySQL> the drop database DROP dATABASE;
eRROR 1008 (HY000): the drop of can not database ‘drop_database’; database does not the exist
// error, can not be deleted ‘drop_database’ database, which does not exist .
MySQL> Database the drop DROP DATABASE IF EXISTS;
Query the OK, 0 rows affected, 1 warning (0.00 sec) // generate a warning Explanation This database does not exist
MySQL> the Create Database DROP DATABASE;
Query the OK, 1 Row affected (0.00 sec)
MySQL> the drop database if exists drop_database; // if exists is determined whether the database exists, there is no error
Query OK, 0 rows affected (0.00 sec)

 
4.4 database connection

Command: use <database name>

Example: If xhkdb database exists, try to access it:
MySQL> use xhkdb;
screen prompts: Database changed

use MySQL statements can notice the db_name database as the default (current) database for subsequent statements. The database remains the default database until the end of the discourse, or until a different release USE statement:
MySQL> USE DB1;
MySQL> the SELECT COUNT (*) the FROM MyTable; # Selects from db1.mytable
MySQL> USE DB2;
MySQL> SELECT COUNT (*) fROM mytable; # selects from db2.mytable

uSE statement for a particular database current mark, will not prevent you from accessing other tables in the database. The following examples from the authors table db1 database access, and access to edit the table from the db2 database:
MySQL> the USE db1;
MySQL> the SELECT AUTHOR_NAME, EDITOR_NAME the FROM author, db2.editor
-> the WHERE author.editor_id = db2.editor.editor_id;

the USE statement is provided for compatibility with Sybase.

Some friends asked, how to exit after the connection. In fact, do not withdraw, after use database, using show databases can query the database for all, if you want to jump to other databases with
use another database name
on it.

4.5 currently selected database

Command: MySQL> SELECT Database ();

the MySQL in the SELECT command is similar to other programming languages in print or write, you can use it to display a string, numeric result, math expressions, and so on. How to use the command in MySQL SELECT special features?

1. Display the version of MYSQL
MySQL> SELECT Version ();
+ ———————– +
| Version () |
+ —— + —————–
| 6.0.4-Alpha-Community Community |
+ ———————- – +
1 Row in SET (0.02 sec)

2. displays the current time
MySQL> SELECT now ();
+ ——————— +
| now () |
+ ——————— +
| 2009-09-15 22:35:32 |
+ ————– + ——-
1 Row in SET (0.04 sec)

3. To display the date
the SELECT DAYOFMONTH (CURRENT_DATE);
+ ——————— + —–
| DAYOFMONTH (CURRENT_DATE) |
+ ————————– +
| 15 |
+ —— + ——————–
1 Row in SET (0.01 sec)

the SELECT MONTH (CURRENT_DATE);
+ ————– + ——-
| MONTH (CURRENT_DATE) |
+ ——————— +
|. 9 |
+ ——— + ————
1 Row in SET (0.00 sec)

the SELECT YEAR (CURRENT_DATE);
+ ——————– +
| YEAR (CURRENT_DATE) |
+ ——————– +
| 2009 |
+ ——————- – +
1 Row in SET (0.00 sec)

4. The display string
MySQL> the SELECT “welecome to My Blog!”;
+ ———————- +
| welecome to My Blog |!
+ ———————- +
| welecome to My Blog |!
+ ———– + ———–
1 Row in SET (0.00 sec)

5. The calculator when using
SELECT ((4 * 4) / 10) + 25;
+ ———– + ———–
| ((4 * 4) / 10) + 25 |
+ ———————- +
| 26.60 |
+ ———————- +
1 Row in SET (0.00 sec)

6. The concatenated string
select CONCAT (f_name, “”, l_name)
the Name the AS
from employee_data
the WHERE title = ‘Marketing Executive’;
+ ————— +
| the Name |
+ ————— +
| Sehgal monica |
| Hal Simlai |
| Joseph Irvine |
+ ————— +
3 rows in SET (0.00 sec)
Note: this use CONCAT () function is used to character string pick up. In addition, we use the results to previously learned AS column ‘CONCAT (f_name, “”, l_name)’ played a pseudonym.

 
5.1 Create a data table

Command: create table <table name> (<field name 1> <Type 1> [, .. <field name n> <type n>]);

for example, to create a table named MyClass,
Field name Digital Type Data Width Is empty Whether the primary key Automatically increase Defaults
id int 4 no primary key auto_increment
name char 20 no
sex int 4 no 0
degree double 16 Yes
MySQL> the Create the Table MyClass (
> the above mentioned id int (4) Not null Primary Key AUTO_INCREMENT ,
> name char (20) Not null,
> Sex int (4) Not null default ‘0’,
> Double Degree (16,2));
5.3 Delete Data Sheet

Command: drop table <table name>

For example: to delete the table named MyClass table
MySQL> the drop the Table MyClass;

the DROP TABLE to cancel one or more tables. You must have the DROP privilege for each table. All table data and table definitions will be canceled, so use this statement to be careful!

Note: For a table with partitions, DROP TABLE permanently cancel the table definition, cancel each partition and cancel all the data stored in these partitions. DROP TABLE will be canceled and the cancellation of the table associated partition definition (.par) file.

For a non-existent table using IF EXISTS to prevent an error. When using IF EXISTS, for each table that does not exist, it generates a NOTE.

RESTRICT and CASCADE can make it easier for the partition. Currently, RESTRICT and CASCADE not work.
Table 5.4 insert data

Command: insert into <table name> [(<1 field name> [, .. <field name n>])] values (value 1) [, (value n)]

Example: To insert a table MyClass two records, which two record indicates: number of scores named Tom 1 is 96.45, No. 2 named Joan score was 82.99, No. 3 named Wang score was 96.5.
mysql> insert into MyClass values (1 , ‘Tom’, 96.45), (2, ‘Joan’, 82.99), (2, ‘Wang’, 96.59);

Note: insert into each table can only be inserted into a record .
5.5 data Query table

1), to query all rows
command: select <Field 1, Field 2, …> from <table name> where <expression>
For example: view all the data in the table MyClass
MySQL> SELECT * from MyClass;

2), before the inquiry a few lines of data
, for example: see the table in the first two rows of data MyClass
MySQL> SELECT * from the order by the above mentioned id MyClass limit 0,2;

SELECT with where ships used to find out more accurate and complex data.
5.6 to delete data in the table
Command: delete from table name where expressions

such as: MyClass delete table records numbered 1
mysql> delete from MyClass where id = 1;

The following is a comparison of before and after the deleted data table.
FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
PHP code as an example below to delete “Persons” table all LastName = ‘Griffin’ records:
<? Php
$ Con = mysql_connect ( “localhost”, “peter”, “abc123”);
if (! $ con)
{
die ( ‘Could not connect:’ mysql_error ().);
}
mysql_select_db ( “my_db”, $ con);
mysql_query ( “DELETE FROM Persons WHERE LastName = ‘Griffin'”); mysql_close ($ con);
?>
After this deletion, the table is this:
FirstName LastName Age
Glenn Quagmire 33

5.7 modify the data in the table

Syntax: update table set field = new value, … where conditions
mysql> update MyClass set name = ‘ Mary’ where id = 1;

example 1: MySQL UPDATE statement is a single table:
the UPDATE [the LOW_PRIORITY] [IGNORE] tbl_name the SET col_name1 = expr1 [, col_name2 = expr2 …] [WHERE where_definition] [ORDER BY …] [LIMIT row_count]

examples of 2: UPDATE statement multi-table:
the UPDATE [the LOW_PRIORITY] [IGNORE] table_references the SET col_name1 = expr1 [, col_name2 = … expr2] [the WHERE where_definition]

the uPDATE syntax can be updated with the new values in the original table rows columns. SET clause indicates which columns to modify and what value should be given. WHERE clause specifies which rows should be updated. If no WHERE clause, all rows are updated. If you specify an ORDER BY clause, in accordance with the designated order of rows to be updated. LIMIT clause to a given limit, limit the number of rows that can be updated.

5.8 increase the field

Command: the ALTER the Table table add field types other;
for example: In Table MyClass added a field passtest, of type int (4), the default value is 0
MySQL> the ALTER the Table MyClass add passtest int ( 4 ) default ‘0’

plus index
mysql> alter table table add index index name (field name 1 [, field name 2 …]);
example: mysql> alter table employee add index emp_name (name);

plus the primary key index
mysql> alter table table name add primary key (field names);
example: mysql> alter table employee add primary key (id);

plus a unique constraint index
mysql> alter table table name add unique index name (field name);
example: mysql> alter table employee add unique emp_name2 (cardnumber);

delete an index
mysql> alter table table name drop index index name;
example: mysql> alter table employee drop index emp_name;

increase the field:
MySQL> the ALTER tABLE table_name the ADD FIELD_NAME field_type;

modify the original field names and type:
MySQL> the ALTER TABLE table_name the CHANGE old_field_name new_field_name field_type;

delete fields:
the MySQL the ALTER TABLE table_name the DROP FIELD_NAME;
5.9 modify the table name

Command: rename table the original table to the new table name;

for example: In Table MyClass name changed to YouClass
MySQL> MyClass to the rename the Table YouClass;

When you execute RENAME, you can not have any locked tables or transaction activity. You also need to have the original table ALTER, and DROP privileges, and the CREATE and INSERT privileges on the new table.

If the multi-table rename, MySQL encounters any errors, it will all be renamed renamed the table back, everything will return to its original state.

RENAME TABLE are added in MySQL 3.23.23.

 
6, the backup database

DOS command in the [url = file: // \\ mysql \\ bin] \\ mysql \\ bin [/ url] to the next directory

1. Export the entire database
export files exist by default mysql \ bin directory
mysqldump -u user name -p database name> exported file name
mysqldump -u USER_NAME -p123456 database_name> outfile_name.sql

2. export a table
mysqldump -u username -p database name watches> export file name
mysqldump -u user_name -p database_name table_name> outfile_name.sql

3. To export a database structure
the mysqldump -u USER_NAME -p -d -add-drop-table database_name> outfile_name.sql
-d no data -add-drop-table before each create statement increases the Table a the drop

4. with language parameter derivation
mysqldump -uroot -p -default-character-set = latin1 -set-charset = gbk -skip-opt database_name> outfile_name.sql

example, aaa database backup to a file back_aaa in:
[root @ test1 root] # CD / Home / Data / MySQL
[root @ test1 MySQL] # the mysqldump -u root -p –opt AAA> back_aaa
7.1 Examples of building a database and build a table of 1

drop database if exists school; // if there is deleted SCHOOL
create database school; // build libraries SCHOOL
use School; // open the library SCHOOL
the Create the Table Teacher // build table TEACHER
(
the above mentioned id int (3) Not null Primary Key AUTO_INCREMENT,
char name (10) Not null,
address VARCHAR (50) default ‘rmohan’
year a Date
); // build table end

// Here is the insert field
insert into teacher values ( “, ‘ allen’, ‘ one india rajesh’ ‘1976-10-10’);
INSERT INTO Teacher values ( ” ‘Jack’, ‘rajesh II’, ‘1975-12-23’);

If you type the above command at mysql prompt can be, but not convenient debugging.
1, you can write the above command as a text file is assumed to be school.sql, and then copied to the c: \\ and state into the DOS directory [url = file: // \\ mysql \\ bin] \\ mysql \\ bin [/ url] , and then type the following command:
MySQL-uroot–p password <c: \\ school.sql
If successful, vacated his party without any display; any error, there will be prompt. (The above command has been debugging, as long as you // uncomment to use).

2, or go to the command line using the mysql> source c: \\ school.sql; school.sql files can also be imported in the database.

7.2 Examples of building a database and build a table of 2

drop database if exists school; // if there is deleted SCHOOL
create database school; // build libraries SCHOOL
use School; // open the library SCHOOL
the Create the Table Teacher // build table TEACHER
(
the above mentioned id int (3) Not null Primary Key AUTO_INCREMENT,
char name (10) Not null,
address VARCHAR (50) default ” rmohan ”,
year a Date
); // build table end

// Here is the insert field
insert into teacher values ( ” ‘ ‘, ” john ” , ” in rmohan, a ”, ” 1976-10-10 ”);
INSERT INTO Teacher values ( ” ”, ” Jack ”, ” in rmohan, a ”, ” 1975-12- 23 ”);

Note: under construction table
1, the ID number field is set to a length of 3: int (3); and it is automatically incremented for each record: auto_increment; and can not be empty: not null; and let him become the main field primary key.

2. Set the NAME field length of 10 characters

3, the ADDRESS field length to 50 characters, and the default value of rmohan.

4, YEAR set the date field.

CentOS 7.0 server installation configuration vsftp

CentOS 7.0 server installation configuration vsftp

First, configure the firewall to open the ports needed to FTP server

CentOS 7.0 is the default firewall as a firewall, here to iptables firewall.
1, closed firewall:

systemctl stop firewalld.service # Stop firewall

systemctl disable firewalld.service # prohibit firewall boot

2. Install iptables firewall

yum install iptables-services # installation

vi /etc/sysconfig/iptables # edit the firewall configuration file

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 21 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 10060:10090 -j ACCEPT

-A INPUT -j REJECT –reject-with icmp-host-prohibited

-A FORWARD -j REJECT –reject-with icmp-host-prohibited

COMMIT

:wq! # Save and exit

systemctl restart iptables.service # final restart firewall configuration to take effect

systemctl enable iptables.service # firewall boot

Description: 21 port is the ftp service port; 10060-10090 port Vsftpd passive mode is required, you can customize the period of greater than 1024 tcp port.
SELINUX

vi /etc/selinux/config

#SELINUX=enforcing # # commented

#SELINUXTYPE=targeted

SELINUX=disabled

:wq!

setenforce 0

Third, install vsftpd

yum install -y vsftpd # install vsftpd

yum install -y psmisc net-tools systemd-devel libdb-devel perl-DBI # installation vsftpd virtual user configuration dependencies

systemctl start vsftpd.service # Start

systemctl enable vsftpd.service # set vsftpd boot

vsftp

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak back up the default profile

Execute the following command set

sed -i “s/anonymous_enable=YES/anonymous_enable=NO/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#anon_upload_enable=YES/anon_upload_enable=NO/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#chown_uploads=YES/chown_uploads=NO/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#async_abor_enable=YES/async_abor_enable=YES/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#ascii_upload_enable=YES/ascii_upload_enable=YES/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#ascii_download_enable=YES/ascii_download_enable=YES/g” ‘/etc/vsftpd/vsftpd.conf’

sed -i “s/#ftpd_banner=Welcome to blah FTP service./ftpd_banner=Welcome to FTP service./g” ‘/etc/vsftpd/vsftpd.conf’

echo -e “use_localtime=YES\nlisten_port=21\nchroot_local_user=YES\nidle_session_timeout=300

\ndata_connection_timeout=1\nguest_enable=YES\nguest_username=vsftpd

\nuser_config_dir=/etc/vsftpd/vconf\nvirtual_use_local_privs=YES

\npasv_min_port=10060\npasv_max_port=10090

\naccept_timeout=5\nconnect_timeout=1” >> /etc/vsftpd/vsftpd.conf

Fifth, the establishment of virtual user list file

touch /etc/vsftpd/virtusers

Edit the virtual user account list file 🙁 first line, second line password, note: do not use the root user name, the system retained)

vi /etc/vsftpd/virtusers

web1
123456
web2
123456
web3
123456
:wq!

Sixth, to generate a virtual user data file

db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db

chmod 600 /etc/vsftpd/virtusers.db # set the PAM authentication files and specify the virtual user database file for reading

Seven, in /etc/pam.d/vsftpd file header by adding the following information (later joined invalid)

Before the amendment to the backup cp /etc/pam.d/vsftpd /etc/pam.d/vsftpdbak
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpdbak

vi /etc/pam.d/vsftpd

auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

Note: If your system is 32-bit, top to lib, otherwise, the configuration fails

Eight, the new system user vsftpd, user directory is /home/wwwroot, user login terminal is set to /bin/false (even if they can not log into the system)
useradd vsftpd -d /home/wwwroot -s /bin/false

chown vsftpd:vsftpd /home/wwwroot -R

chown www:www /home/wwwroot -R ## If the virtual host user user www, the need for such settings.

Nine, to create a virtual user’s personal profile Vsftp

mkdir /etc/vsftpd/vconf

cd /etc/vsftpd/vconf

touch web1 web2 web3 # to create three virtual user profile here

mkdir -p /home/wwwroot/web1/http/

vi web1 # web1 edit user profiles, with other similar configuration file

local_root=/home/wwwroot/web1/http/

write_enable=YES

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

Ten, the final restart vsftpd server

systemctl restart vsftpd.service

???

guest_username=vsftpd # user-specified virtual host user (new user is in front of us)

guest_username=www # If the ftp directory is pointing to the root directory of the site for uploading Web site, you can specify the user’s virtual host user accounts to run nginx www, avoid many problems permission settings

Sample doc is attached

 

 

doc1

Page 30 of 164« First...1020...2829303132...405060...Last »