普通方法安装

安装YUM Repo

由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件。

1
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

然后进行repo的安装:

1
rpm -ivh mysql57-community-release-el7-9.noarch.rpm

安装mysql

1
yum install mysql-server

启动mysql

1
service mysqld start

配置MySQL

获取安装时的临时密码:

1
grep 'temporary password' /var/log/mysqld.log

倘若没有

  • (1)删除原来安装过的mysql残留的数据
    1
    rm -rf /var/lib/mysql
  • (2)再启动mysql
    1
    service mysqld start

登录

1
mysql -u root -p

登录成功后需要先修改密码:

1
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

在设置密码时,但密码在简单时会出现ERROR 1819 (HY000): Your password does not satisfy the current policy requirements的错误
设置参数:

1
2
set global validate_password_policy=0;
set global validate_password_length=1;

这时再设置密码就不错报错了。

修改登录权限

1
2
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;

查看mysql运行状态

1
service mysqld status

停止mysql

1
service mysqld stop

使用docker-compsoe安装

创建docker-compose.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: '2'
services:
db:
image: 'mysql/mysql-server:5.7'
restart: always
container_name: mysql57
environment:
MYSQL_USER: 用户名
MYSQL_PASSWORD: 密码
MYSQL_DATABASE: 初始创建的数据库
MYSQL_ROOT_PASSWORD: root用户密码
ports:
- '3306:3306'//映射端口

启动docker-compsoe

1
2
启动docker-compose(后台模式,不打印日志)
docker-compose up -d

进入容器创建用户

进入docker中的mysql容器

查看mysql容器的id

1
docker ps

进入docker容器命令行

1
docker exec -it mysql容器id bash

进入mysql命令行

1
mysql -u root -p

可以使用docker配置文件中创建的用户也可以创建新用户

创建新用户:

1
create user 'admin001'@'%' identified by '123456';

删除用户:

1
DROP USER 'admin001'@'%';

给用户赋权限:

1
2
grant all privileges on *.* to 'admin001'@'%' identified by '123456';
flush privileges;

1
lsof -i:端口

1
sudo systemctl stop firewalld.service && sudo systemctl disable firewalld.service

1
$(".html").animate({scrollTop:'0px'}, 200);

1
SELECT DISTINCT(u.userId) FROM `user` u where u.status='1';

poi导出

使用poi导出大量数据时,可以使用 SXSSFWorkbook

使用方法:

  1. 导入poi包及poi-ooxml包
1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
  1. 具体代码
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
package com.liuyy.excel;

import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;

/**
* @author liuyy
* @className PoiExcelDemo
* @description TODO
* @date 2019/7/26 16:55
**/
public class PoiExcelDemo {
public static void main(String[] args) {
exportExcel("数据导出.xls");
}
public static void exportExcel(String fileName){
SXSSFWorkbook workbook = new SXSSFWorkbook();
//输出Excel文件
FileOutputStream output = null;
try {
//添加Worksheet(不添加sheet时生成的xls文件打开时会报错)
String sheetName = "数据导出";
SXSSFSheet sheet = workbook.createSheet(sheetName);
// 设置缺省列高
sheet.setDefaultRowHeightInPoints(20);
// 设置缺省列宽
sheet.setDefaultColumnWidth(20);
// 设置字体
Font fontStyle = workbook.createFont();
fontStyle.setFontName("宋体");
fontStyle.setFontHeightInPoints((short) 20);
// 创建XSSFRow对象
// 创建第一行-表头
SXSSFRow rowHead = sheet.createRow(0);
for (int i = 0; i < 8; i++) {
//创建XSSFCell对象
SXSSFCell cellHead = rowHead.createCell(i);
//设置单元格的值
cellHead.setCellValue(i);
}

// 创建具体数据
for (int i = 0; i < 100; i++) {
// 第i+1行
SXSSFRow row = sheet.createRow(i + 1);
row.createCell(0).setCellValue("第1列");
row.createCell(1).setCellValue("第2列");
row.createCell(2).setCellValue("第3列");
row.createCell(3).setCellValue("第4列");
row.createCell(4).setCellValue("第5列");
row.createCell(5).setCellValue("第6列");
}
output = new FileOutputStream(fileName);
workbook.write(output);
output.flush();
workbook.close();
output.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
workbook.close();
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
  1. 结果如果所示:
{% asset_img pasted-5.png excel %}

table导出

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//获取表格
var exportFileContent = document.getElementById("showTable").outerHTML;
//设置格式为Excel,表格内容通过btoa转化为base64,此方法只在文件较小时使用(小于1M)
//exportFileContent = window.btoa(unescape(encodeURIComponent(exportFileContent)));
//var link = "data:"+MIMEType+";base64," + exportFileContent;

//使用Blob
var blob = new Blob([exportFileContent], {type: "text/plain;charset=utf-8"});
//解决中文乱码问题
blob = new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
//设置链接
var link = window.URL.createObjectURL(blob);

var a = document.createElement("a"); //创建a标签
a.download = filenName+".xls"; //设置被下载的超链接目标(文件名)
a.href = link; //设置a标签的链接
document.body.appendChild(a); //a标签添加到页面
a.click(); //设置a标签触发单击事件
document.body.removeChild(a); //移除a标签

计算机中的整数二进制

正数

正数的二进制正常表示
如整数5的二进制表示为
0000 0000 0000 0000 0000 0000 0000 0101

负数

在计算机中,负数以其正值的补码形式表达

如:-17,他的正值(17)二进制为:
0000 0000 0000 0000 0000 0000 1001 0001

补码的计算方式为:反码+1;

17的反码为:
1111 1111 1111 1111 1111 1111 0110 1110

可得-17为:
1111 1111 1111 1111 1111 1111 0110 1111

0%