0%

在安装完ubuntu的时候

只有自己设置的非root的帐号和密码

但是又要用root密码怎么办呢?

1
2
3
4
hisen@ubuntu-1:~$ sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

上面输入的密码就是你的root密码

检测一下

1
2
3
hisen@ubuntu-1:~$ su
Password:
root@ubuntu-1:/home/hisen#

通过,至此结束

安装需求:

  1. 64位的系统 Linux/Unix/Mac
  2. 64bit JDK 1.8+;
  3. Maven 3.2.x;
  4. Git (一般自带)

如果还未安装jdk、maven建议查看教程:点击查看

Clone & Build

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
git clone -b develop https://github.com/apache/incubator-rocketmq.git
cd incubator-rocketmq
mvn -Prelease-all -DskipTests clean install -U
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Apache RocketMQ 4.2.0-incubating-SNAPSHOT .......... SUCCESS [01:07 min]
[INFO] rocketmq-remoting 4.2.0-incubating-SNAPSHOT ........ SUCCESS [ 15.749 s]
[INFO] rocketmq-common 4.2.0-incubating-SNAPSHOT .......... SUCCESS [ 10.243 s]
[INFO] rocketmq-client 4.2.0-incubating-SNAPSHOT .......... SUCCESS [ 11.638 s]
[INFO] rocketmq-store 4.2.0-incubating-SNAPSHOT ........... SUCCESS [ 13.108 s]
[INFO] rocketmq-srvutil 4.2.0-incubating-SNAPSHOT ......... SUCCESS [ 2.051 s]
[INFO] rocketmq-filter 4.2.0-incubating-SNAPSHOT .......... SUCCESS [ 3.917 s]
[INFO] rocketmq-broker 4.2.0-incubating-SNAPSHOT .......... SUCCESS [ 8.726 s]
[INFO] rocketmq-tools 4.2.0-incubating-SNAPSHOT ........... SUCCESS [ 6.002 s]
[INFO] rocketmq-namesrv 4.2.0-incubating-SNAPSHOT ......... SUCCESS [ 2.726 s]
[INFO] rocketmq-logappender 4.2.0-incubating-SNAPSHOT ..... SUCCESS [ 3.514 s]
[INFO] rocketmq-openmessaging 4.2.0-incubating-SNAPSHOT ... SUCCESS [ 2.668 s]
[INFO] rocketmq-example 4.2.0-incubating-SNAPSHOT ......... SUCCESS [ 2.390 s]
[INFO] rocketmq-filtersrv 4.2.0-incubating-SNAPSHOT ....... SUCCESS [ 2.145 s]
[INFO] rocketmq-test 4.2.0-incubating-SNAPSHOT ............ SUCCESS [ 5.428 s]
[INFO] rocketmq-distribution 4.2.0-incubating-SNAPSHOT .... SUCCESS [ 27.002 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 03:07 min
[INFO] Finished at: 2017-07-02T01:35:40+08:00
[INFO] Final Memory: 60M/247M
[INFO] ------------------------------------------------------------------------
cd distribution/target/apache-rocketmq

Start Name Server

1
2
3
nohup sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...

Start Broker

1
2
3
nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...

Send & Receive Messages

1
2
3
4
5
6
7
Before sending/receiving messages, we need to tell clients the location of name servers. RocketMQ provides multiple ways to achieve this. For simplicity, we use environment variable NAMESRV_ADDR
export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...

Shutdown Servers

1
2
3
4
5
6
7
sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK

sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK

powerdesigner Oracle mysql comment 缺少右括号

今天人家给我个powerdesigner设计好的表

要我去间数据库,直接复制出来去oracle执行,结果报错。

在comment附近,如果把comment去掉则可以正确执行

最后找到罪魁祸首:powerdesigner没有设置对数据库

解决办法,在powerdesigner页面

1
database-->change curren DBMS 

上面是设置你需要的数据库

下面是为更改前的数据库

有时候需要行转列或者列转行

在Oracle 11g中,Oracle 又增加了2个查询:pivot(行转列) 和unpivot(列转行)

下面是在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
mysql> select * from test;
+------+------+--------+
| id | age | weigth |
+------+------+--------+
| 1 | 1 | 3 |
| 1 | 2 | 2 |
| 1 | 3 | 1 |
| 2 | 5 | 6 |
+------+------+--------+
4 rows in set (0.00 sec)

#根据ID分组
mysql> select group_concat(age) from test group by id;
+-------------------+
| group_concat(age) |
+-------------------+
| 1,2,3 |
| 5 |
+-------------------+
2 rows in set (0.01 sec)

#不分组
mysql> select group_concat(age) from test;
+-------------------+
| group_concat(age) |
+-------------------+
| 1,2,3,5 |
+-------------------+
1 row in set (0.00 sec)

下面这个存储过程是查找数据库中某个字段值为:hisen 的表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
declare
l_cnt varchar2(20);
v_sql varchar2(4000);
v_tablename varchar(200);
cursor cursor_jsdx is select 'select count(*) from ' || table_name || ' where NAME=''hisen''',table_name from user_tab_columns where column_name='NAME';
--注:这里的字段名要大写
begin
open cursor_jsdx;
Loop
fetch cursor_jsdx into v_sql,v_tablename;
exit when cursor_jsdx%notfound;
execute immediate v_sql into l_cnt;
if l_cnt >0 then
---如果该表有那内容的就打印那个表的名字。
dbms_output.put_line(v_tablename);
end if;
end loop;
Close cursor_jsdx;
end;

Java.sql.SQLException: Connections could not be acquired from the underlying database

这个错误出现的原因有的说是因为jdbc配置文件写错了

正确的写法是:

1
2
3
4
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.jdbcUrl=jdbc:mysql://localhost:3306/test
c3p0.user=root
c3p0.password=root

而不是

1
2
3
4
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
user=root
password=root

但是我遇到的不是如此

后来发现是因为maven出问题了,jar包没有加载进项目

这是在starkoverflow上看到的回答

1
In my case it was problem that c3p0-0.9.2.1.jar file was not copied by maven into src/main/webapp/web-inf/libs

最后maven重新install之后就解决了

具体代码如下,这里获取出来的文件大小是准确的

FileInputStream方式获取出来的大小会有差异

NIO与IO的对比详见:NIOCopy.Java

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
/**
* 利用NIO进行读写文件
*
* @param oldFileName 原文件的路径
* @param newFileName 新文件的路径
*/
public static void nioCopy(String oldFileName, String newFileName) {
try {
FileChannel fileChannelIn = new FileInputStream(new File(oldFileName)).getChannel();
FileChannel fileChannelOut = new FileOutputStream(new File(newFileName)).getChannel();
//获取文件大小
long size = fileChannelIn.size();
System.out.printf("文件大小为:%s byte \n",size);
//缓冲
ByteBuffer byteBuffer = ByteBuffer.allocate(1024);

long start = System.currentTimeMillis();
while (fileChannelIn.read(byteBuffer) != -1) {
//准备写
byteBuffer.flip();
fileChannelOut.write(byteBuffer);
//准备读
byteBuffer.clear();
}
long end = System.currentTimeMillis();
System.out.printf("NIO方式复制完成,耗时 %s 秒\n",(end-start)/1000);
//关闭
fileChannelIn.close();
fileChannelOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

这里主要是介绍了几种redis支持的数据结构,以及操作方法

官网地址:http://try.redis.io/

我的redis是安装在linux虚拟机,通过Xshell操作,显示可能跟cmd不大一样

但是操作都是一样的

具体操作如下:

Read more »

hisen库中有一个post表,数据20w,非重复数据20条;

结构如下

1
2
3
4
5
6
7
8
9
mysql> describe post;
+---------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(255) | YES | MUL | NULL | |
| content | varchar(2550) | YES | | NULL | |
+---------+---------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

添加普通索引

1
2
3
mysql> alter table post add index index_post_title (title);
Query OK, 0 rows affected (1.22 sec)
Records: 0 Duplicates: 0 Warnings: 0

删除索引

1
2
3
mysql> drop index index_post_title on post;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

添加索引之后查询速度明显加快

1
2
3
4
mysql> select count(title) from post group by title;
20 rows in set (0.25 sec)
#加了索引之后
20 rows in set (0.08 sec)

使用索引的情况

  1. 表的主关键字:自动建立唯一索引
  2. 表的字段唯一约束:ORACLE利用索引来保证数据的完整性
  3. 直接条件查询的字段
  4. 在SQL中用于条件约束的字段
  5. 查询中与其它表关联的字段
  6. 查询中排序的字段
  7. 查询中统计或分组统计的字段

不使用索引的情况

  1. 表记录太少
  2. 经常插入、删除、修改的表
  3. 数据重复且分布平均的表字段:假如10万数据只有A、B状态,且A、B各50%,这样建立索引就不会提速
  4. 经常和主字段一块查询但主字段索引值比较多的表字段

MySql在建立索引优化时需要注意的问题

Read more »

数据库名称表名
employeesemployees
hisenemployee

现在想把第一行的数据导入到第二行,具体如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
mysql> describe employees;
+------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------+------+-----+---------+-------+
| emp_no | int(11) | NO | PRI | NULL | |
| birth_date | date | NO | | NULL | |
| first_name | varchar(14) | NO | | NULL | |
| last_name | varchar(16) | NO | | NULL | |
| gender | enum('M','F') | NO | | NULL | |
| hire_date | date | NO | | NULL | |
+------------+---------------+------+-----+---------+-------+
6 rows in set

mysql> select count(*) from employees;
+----------+
| count(*) |
+----------+
| 300024 |
+----------+
1 row in set

employees数据库中的employees表有30万数据

我想把这个数据导出到另外一个数据库hisen中的employee表中

具体操作如下

Read more »