0%

Employees数据库是mysql官方提供的一个测试用数据库

里面含有几十万条数据。

找了好久也没有找到比较匹配的题目

就找了个匹配度比较高的题来练习,如果你还没有导入Employees Sample Database

请参考:点击导入Employees

本次操作在Xshell中完成,也就是mysql命令行。

简单的操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#登陆数据库
hisen@ubuntu:/$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| employees |
| log4j |
| mysql |
| performance_schema |
| ssm |
| sys |
+--------------------+
7 rows in set (0.00 sec)

mysql> use employees
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------+
| Tables_in_employees |
+----------------------+
| current_dept_emp |
| departments |
| dept_emp |
| dept_emp_latest_date |
| dept_manager |
| employees |
| salaries |
| titles |
+----------------------+
8 rows in set (0.00 sec)

mysql> select * from employees limit 10;
+--------+------------+------------+-----------+--------+------------+
| emp_no | birth_date | first_name | last_name | gender | hire_date |
+--------+------------+------------+-----------+--------+------------+
| 10001 | 1953-09-02 | Georgi | Facello | M | 1986-06-26 |
| 10002 | 1964-06-02 | Bezalel | Simmel | F | 1985-11-21 |
| 10003 | 1959-12-03 | Parto | Bamford | M | 1986-08-28 |
| 10004 | 1954-05-01 | Chirstian | Koblick | M | 1986-12-01 |
| 10005 | 1955-01-21 | Kyoichi | Maliniak | M | 1989-09-12 |
| 10006 | 1953-04-20 | Anneke | Preusig | F | 1989-06-02 |
| 10007 | 1957-05-23 | Tzvetan | Zielinski | F | 1989-02-10 |
| 10008 | 1958-02-19 | Saniya | Kalloufi | M | 1994-09-15 |
| 10009 | 1952-04-19 | Sumant | Peac | F | 1985-02-18 |
| 10010 | 1963-06-01 | Duangkaew | Piveteau | F | 1989-08-24 |
+--------+------------+------------+-----------+--------+------------+
10 rows in set (0.00 sec)
#统计各部门曾经拥有的员工数量
mysql> select dept_no,count(*) emp_sum
-> from dept_emp
-> group by dept_no
-> order by emp_sum desc;
+---------+---------+
| dept_no | emp_sum |
+---------+---------+
| d005 | 85707 |
| d004 | 73485 |
| d007 | 52245 |
| d009 | 23580 |
| d008 | 21126 |
| d001 | 20211 |
| d006 | 20117 |
| d003 | 17786 |
| d002 | 17346 |
+---------+---------+
9 rows in set (0.63 sec)
#创建视图
mysql> CREATE VIEW test AS
-> SELECT dept_no, COUNT(*) AS emp_sum
-> FROM dept_emp
-> GROUP BY dept_no
-> ORDER BY emp_sum DESC
-> ;
Query OK, 0 rows affected (0.16 sec)
mysql> select * from test;
+---------+---------+
| dept_no | emp_sum |
+---------+---------+
| d005 | 85707 |
| d004 | 73485 |
| d007 | 52245 |
| d009 | 23580 |
| d008 | 21126 |
| d001 | 20211 |
| d006 | 20117 |
| d003 | 17786 |
| d002 | 17346 |
+---------+---------+
9 rows in set (0.11 sec)
#联合查询,加上部门名称
mysql> select test.dept_no,emp_sum,dept_name
-> from test,departments
-> where test.dept_no = departments.dept_no;
+---------+---------+--------------------+
| dept_no | emp_sum | dept_name |
+---------+---------+--------------------+
| d009 | 23580 | Customer Service |
| d005 | 85707 | Development |
| d002 | 17346 | Finance |
| d003 | 17786 | Human Resources |
| d001 | 20211 | Marketing |
| d004 | 73485 | Production |
| d006 | 20117 | Quality Management |
| d008 | 21126 | Research |
| d007 | 52245 | Sales |
+---------+---------+--------------------+
9 rows in set (0.16 sec)

练习题目和答案:

建议看看输出的结果自己写下sql,不要单纯的复制粘贴。

因为数据量比较大, 很多时候我都加了5条数据的限制。

Read more »

linux查看日志文件内容命令tail、cat、tac、head、echo

tail -f test.log

你会看到屏幕不断有内容被打印出来. 这时候中断第一个进程Ctrl-C,

cat -n hisen.log | grep ‘907’

在文件当中查找指定的内容,这里是查询:907


linux 如何显示一个文件的某几行(中间几行)

从第3000行开始,显示1000行。即显示3000~3999行

1
cat filename | tail -n +3000 | head -n 1000

显示1000行到3000行

1
cat filename| head -n 3000 | tail -n +1000

*注意两种方法的顺序
分解:

  1. tail -n 1000:显示最后1000行
  2. tail -n +1000:从1000行开始显示,显示1000行以后的
  3. head -n 1000:显示前面1000行

用sed命令
sed -n ‘5,10p’ filename 这样你就可以只查看文件的第5行到第10行。

例:cat mylog.log | tail -n 1000 #输出mylog.log 文件最后一千行


cat主要有三大功能:

1.一次显示整个文件。$ cat filename

2.从键盘创建一个文件。$ cat > filename

只能创建新文件,不能编辑已有文件.

3.将几个文件合并为一个文件: $cat file1 file2 > file

参数:

-n 或 –number 由 1 开始对所有输出的行数编号

-b 或 –number-nonblank 和 -n 相似,只不过对于空白行不编号

-s 或 –squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行

-v 或 –show-nonprinting

例:

把 textfile1 的档案内容加上行号后输入 textfile2 这个档案里

1
cat -n textfile1 > textfile2

把 textfile1 和 textfile2 的档案内容加上行号(空白行不加)之后将内容附加到 textfile3 里。

1
cat -b textfile1 textfile2 >> textfile3

把test.txt文件扔进垃圾箱,赋空值test.txt

1
cat /dev/null > /etc/test.txt

注意:>意思是创建,>>是追加。千万不要弄混了。


tac (反向列示)

tac 是将 cat 反写过来,所以他的功能就跟 cat 相反, cat 是由第一行到最后一行连续显示在萤幕上,

而 tac 则是由最后一行到第一行反向在萤幕上显示出来!


在Linux中echo命令用来在标准输出上显示一段字符,比如:
echo “the echo command test!”

这个就会输出“the echo command test!”这一行文字!

echo “the echo command test!”>a.sh

这个就会在a.sh文件中输出“the echo command test!”这一行文字!

该命令的一般格式为: echo [ -n ] 字符串其中选项n表示输出文字后不换行;字符串能加引号,也能不加引号。

用echo命令输出加引号的字符串时,将字符串原样输出;

用echo命令输出不加引号的字符串时,将字符串中的各个单词作为字符串输出,各字符串之间用一个空格分割。

一些实例

Read more »

之前安装过第三方的搜索服务,贼蛋疼。都不免费了。

也有自己安装插件,然后写js的,麻烦

后来找到两个插件,安装之后就搞定了

感谢开发的作者!!!

安装插件

记得要在站点根目录执行下面的安装操作

1.安装 hexo-generator-search

1
npm install hexo-generator-searchdb --save

2.安装 hexo-generator-searchdb

1
npm install hexo-generator-searchdb --save
Read more »

Windows、Linux、Mac OS X多个平台都可以用

据我观察这个数据库可视化工具很不错,基于Java

以各种驱动来连接数据库,也就是说Java支持的数据库都可以用他连接

挺好用的,免费!!!

安装之后新建连接,选择你要链接的数据库,配置一下就好了。

下载地址

官网下载地址

快捷键

1
2
3
4
5
6
#Shift + Home选中当前光标到行首
#Shift + End选中当前光标到行尾
#Shift + ↑/↓/←/→ 移动光标并且选中
#Alt + X 执行选中的sql
#Ctrl + Enter 执行当前光标所在行的sql
#Ctrl + Alt + F 格式化SQL(file -> properties -> +SQL Editor -> SQL formatting)

MySQL 官方是有一个自带的数据库,名为:Employees Sample Database

官网介绍:Employees Sample Database

表名中文
department部门表
dept_emp部门员工任职期表(按部门&时期)
dept_manager部门经理任职期表(按时期)
employees员工详情表
salaries员工薪资表(按时期)
title员工职称表(按时期)
导入的操作过程,在ubuntu上进行操作
Read more »

想要获取root权限,提示如下

1
2
3
hisen@ubuntu:/var/lib$ su
Password:
su: Authentication failure

解决办法

1
2
3
4
5
6
7
hisen@ubuntu:$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
hisen@ubuntu:$ su
Password:
root@ubuntu:# cd mysql

重新设置一下密码即可,我这边装的时候设置的用户是:hisen

刚刚重新设置的密码就是你装系统的时候设置的用户密码。

一直想弄个格式化代码,后来发现很多人用谷歌的,于是也来整一份

保存一份google code的xml,链接有最新的
intellij-Java-google-style.xml
设置方法如下:Setting -> Editor -> Code Stytle -> Java

最后一步就选择你存放之前保存的xml

然后就大功告成,来个对比

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.hisen.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
* Created by hisenyuan on 2017/3/23 at 18:02.
*/
public class test {
public static void main(String[] args) {String s = "{'A':'a'}";
JSONObject obj= JSON.parseObject(s);
System.out.println(obj.get("A"));
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package com.hisen.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
* Created by hisenyuan on 2017/3/23 at 18:02.
*/
public class test {

public static void main(String[] args) {
String s = "{'A':'a'}";
JSONObject obj = JSON.parseObject(s);
System.out.println(obj.get("A"));
}
}

在计算机屏幕上,一个汉字要占两个英文字符的位置,人们把一个英文字符所占的位置称为”半角”,

相对地把一个汉字所占的位置称为”全角”。在汉字输入时,系统提供”半角”和”全角”两种不同的输入状态,

但是对于英文字母、符号和数字这些通用字符就不同于汉字,在半角状态它们被作为英文字符处理;

而在全角状态,它们又可作为中文字符处理。

半角和全角切换方法:单击输入法工具条上的按钮或按键盘上的Shift+Space键来切换。

1、全角:指一个字符占用两个标准字符位置。

汉字字符和规定了全角的英文字符及国标GB2312-80中的图形符号和特殊字符都是全角字符。一般的系统命令是不用全角字符的,只是在作文字处理时才会使用全角字符。


2、半角:指一字符占用一个标准的字符位置。

通常的英文字母、数字键、符号键都是半角的,半角的显示内码都是一个字节。在系统内部,以上三种字符是作为基本代码处理的,所以用户输入命令和参数时一般都使用半角。


3、全角与半角各在什么情况下使用?

全角占两个字节,半角占一个字节。

半角全角主要是针对标点符号来说的,全角标点占两个字节,半角占一个字节,而不管是半角还是全角,汉字都还是要占两个字节。

在编程序的源代码中只能使用半角标点(不包括字符串内部的数据)

在不支持汉字等语言的计算机上只能使用半角标点(其实这种情况根本就不存在半角全角的概念)

对于大多数字体来说,全角看起来比半角大,当然这不是本质区别了。


4、全角和半角的区别
全角就是字母和数字等与汉字占等宽位置的字。半角就是ASCII方式的字符,

在没有汉字输入法起做用的时候输入的字母数字和字符都是半角的。

在汉字输入法出现的时候,输入的字母数字默认为半角,但是标点则是默认为全角,

可以通过鼠标点击输入法工具条上的相应按钮来改变。


5、关于“全角”和“半角”:

全角:是指中GB2312-80(《信息交换用汉字编码字符集·基本集》)中的各种符号。

半角:是指英文件ASCII码中的各种符号。

全角状态下字母、数字符号等都会占两个字节的位置,也就是一个汉字那么宽,半角状态下,

字母数字符号一般会占一个字节,也就是半个汉字的位置,全角半角对汉字没有影响。

有两种方式可以判断:

1:通过正则表达式来进行判断 [^\x00-\xff]

2: 通过字符编码的范围进行判断.

通过打印所有的字符发现:

  1. 半角字符是从33开始到126结束
  2. 与半角字符对应的全角字符是从65281开始到65374结束
  3. 其中半角的空格是32.对应的全角空格是12288
  4. 半角和全角的关系很明显,除空格外的字符偏移量是65248(65281-33 = 65248)

具体的代码如下:

Read more »

idea涉及编码的地方都改了
主要是编译时候的编码,tomcat的编码,以及idea配置里面的编码

一、idea配置文件

1
\HOME\IntelliJ IDEA 2016.3.4\bin\idea64.exe.vmoptions

增加一行:-Dfile.encoding=UTF-8

二、编译参数

1
2
File -> Settings -> Build, Execution, Deployment
-> Compiler -> Java Compiler -> Addition command line parameters

在空格里面添加:-encoding utf-8

三、工程编码

1
File -> Settings -> Editor -> File Encodings

此页面三个地方都选择UTF-8

四、tomcat参数

1
Run/debug Configuration tomcat

VM options:-Dfile.encoding=UTF-8

之前老是出现

1
2
Application Server was not connected before run configuration stop, 
reason: Unable to ping server at localhost:1099

我遇到这个问题一般是这些原因:

  1. 这个端口被占用,一般进程管理把所有Java进程杀了可以解决
  2. 由于在IDEA中错误的给tomcat添加了参数,比如下面这个。去掉即可

这是下VM option中加了:-URIEncoding=UTF-8

1
2
3
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -URIEncoding=UTF-8