MySQL查询所有视图并给用户授予指定视图权限

视图其实就是一张虚拟的表,所有也可以认为是一张表,MySQL查询所有视图:

show table status where comment='view'\G;

查询视图结构:

 DESC master_data_user;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| username  | varchar(255) | YES  |     | NULL    |       |
| org_id    | varchar(255) | YES  |     | NULL    |       |
| status    | varchar(255) | YES  |     | NULL    |       |
| name      | varchar(255) | YES  |     | NULL    |       |
| org_name  | varchar(255) | YES  |     | NULL    |       |
| email     | varchar(255) | YES  |     | NULL    |       |
| telephone | varchar(255) | YES  |     | NULL    |       |
| post      | varchar(255) | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
8 rows in set (0.00 sec)

或者

SHOW TABLE STATUS LIKE 'master_data_user'\G;
*************************** 1. row ***************************
           Name: master_data_user
         Engine: NULL
        Version: NULL
     Row_format: NULL
           Rows: NULL
 Avg_row_length: NULL
    Data_length: NULL
Max_data_length: NULL
   Index_length: NULL
      Data_free: NULL
 Auto_increment: NULL
    Create_time: NULL
    Update_time: NULL
     Check_time: NULL
      Collation: NULL
       Checksum: NULL
 Create_options: NULL
        Comment: VIEW
1 row in set (0.00 sec)

创建data_view用户并授予单个视图权限:

grant select,show view on escdb.master_data_org to data_view@'192.168.%' IDENTIFIED BY 'xxxxxxx';
grant select,show view on escdb.master_data_user to data_view@'192.168.%' ;
flush privileges;

data_view登录后即只能查看master_data_org和master_data_user视图;
查看当前登录用户权限:

 show grants;
+----------------------------------------------------------------------------------+
| Grants for data_view@192.168.%                                                   |
+----------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'data_view'@'192.168.%'                                    |
| GRANT SELECT, SHOW VIEW ON `escdb`.`master_data_org` TO 'data_view'@'192.168.%'  |
| GRANT SELECT, SHOW VIEW ON `escdb`.`master_data_user` TO 'data_view'@'192.168.%' |
+----------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

河边

一个人的河边,经常能看见钓鱼大叔,基本很少见年轻人钓鱼;
美人蕉,菊花,香彩雀,风车草,绿化做的挺好;


---阅读剩余部分---

Linux中FIN_WAIT2链接过多的解决方法

在对erp老的架构进行改造中,对外前端使用了Nginx,部署在CentOS中,通过查看当前系统链接发现有不少FIN_WAIT2链接:

[root@hd_my_n1 /]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
SYN_RECV 30
ESTABLISHED 968
FIN_WAIT2 301
TIME_WAIT 145

服务端由于某种原因关闭连接,如KEEPALIVE的超时,这样,作为主动关闭的服务端一方就会进入 FIN_WAIT2状态,但TCP/IP协议栈有个问题,FIN_WAIT2状态是没有超时的(不象TIME_WAIT状态),所以如果CLIENT不关闭,这个FIN_WAIT_2状态将保持到系统重新启动,越来越多的FIN_WAIT_2状态会致使内核crash。
解决方法如下:
修改内核配置vim /etc/sysctl.conf ,加入以下内容:

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_max_syn_backlog = 8192

然后执行

/sbin/sysctl -p

让参数生效。
参数说明:

net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1  表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。
net.ipv4.tcp_fin_timeout  修改系統默认的 TIMEOUT 时间
net.ipv4.tcp_max_syn_backlog = 8192  表示SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数。

参考:CentOS下TIME_WAIT过多-问题处理方法

nginx warn an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/3/47/0003311473 while reading upstream报错解决方法

今天发现nginx的log里面有报错,log如下

2019/06/10 19:01:46 [warn] 8294#0: *231715335 an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/3/47/0003311473 while reading upstream, client: 144.123.15.66, server: oa.xxx.com.cn, request: "GET /sys/attachment/sys_att_main/sysAttMain.do?method=readDownload&fdId=16b406e3861578ee83d15344deb88105&open=1 HTTP/1.1", upstream: "http://10.254.2.16:80/sys/attachment/sys_att_main/sysAttMain.do?method=readDownload&fdId=16b406e3861578ee83d15344deb88105&open=1", host: "oa.xxx.com.cn", referrer: "http://oa.xxx.com.cn/km/review/km_review_main/kmReviewMain.do?method=view&fdId=16b4063ca15ddfca4ed8e3747d09968f"
2019/06/10 19:01:52 [warn] 8292#0: *231712177 an upstream response is buffered to a temporary file /usr/local/nginx/proxy_temp/4/47/0003311474 while reading upstream, client: 115.173.28.199, server: aqhcrm.xxx.com.cn, request: "GET /weixinfile/bonuspic/ebd192724baf49e782eb89a9f1b78e3f.png HTTP/1.1", upstream: "http://10.254.2.21:80/weixinfile/bonuspic/ebd192724baf49e782eb89a9f1b78e3f.png", host: "aqhcrm.xxx.com.cn", referrer: "http://aqhcrm.xxx.com.cn/modules/weixin/bonusSelf.html"

从error日志来看是nginx某一块的buffer设置的太小,(包含response header和response body)导致response结果不得不临时写到文件中,解决办法:
在nginx的http段,或location段增加如下参数,参数值根据实际应用需求调整,

proxy_buffering on;
client_max_body_size 500M;
client_body_buffer_size 500M;
proxy_buffer_size 5120k;
proxy_buffers 2560 5120k;
proxy_busy_buffers_size 5120k;
proxy_temp_file_write_size 5120k;

最后重启nginx报错日志消失;

炎炎夏日

夏天到了,看天气预报咸阳的温度比上海还热,不过北方的天气是早晚温差大,中午很热,但是早晚还好;

人是一个惰性动物,冬天怕冷,夏天怕热;

行动比想法更难,做比想难,坚持!行动起来。

---阅读剩余部分---

Flask使用pymysql后出现Warning:1366的解决办法

Flask项目中,运行python models.py时报错如下:

C:\Users\ice\.virtualenvs\blog-edDN3LWE\lib\site-packages\pymysql\cursors.py:170: Warning: (1366, "Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...' for column 'VARIABLE_VALU
E' at row 485")
  result = self._query(query)

原因是MySQL5.7数据库使用的是utf8mb4编码,使用pymysql会报1366警告,但是数据还是能执行操作,解决方法更换为mysql-connector-python

pip install mysql-connector

models.py里面使用:

import mysql.connector
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql+mysqlconnector://账号:密码@localhost/appname"

然后执行就不会报错了^o^

博客更换域名

以前的域名是unixso.com 目前已更换为unixso.com 更短,mhl这个只是名字里面第一个字母,比较好记,这次会一直使用下去;

看山不是山

很多时候,在看一些事情的时候,表面上看起来貌似很简单,实际上很深入的了解后,确实不简单;特别是在技术方面和项目方面;

越深入越发现自己无知,很多东西不了解;

可能你的了解的只是冰山一角;

iceberg.jpg

SQL Server 2014 创建只读用户

SQLServer系列创建用户基本相似,此处以2014版本为例,创建bpm_r用户为只读用户,仅可读取H3Cloud数据库权限,操作方法如下:
1、打开【Microsoft SQLServer Management Studio】,用管理员账户登录。
2、找到【安全性】,打开,可以看到【登录名】,在上面右键,选择【新建登录名】。
3、在【常规】选项中,输入登录名,选择身份验证方式。这里我选用了【SQL Server 身份验证】同时,勾掉【强制实施密码策略】,输入账号、密码等信息,如下图:
1.png
4、在右侧的【用户映射】选项卡中,【映射到此登录名的用户】选择该用户可以操作的数据库。针对每一个数据库,在下方【数据库角色成员身份】中,选择【db_datareader】和【public】
如下图:
2.png
确定后即可使用bpm_r用户登录数据库,数据库上最好做下IP策略设置;

Ubuntu 18.04更换国内镜像源提高安装更新速度

Ubuntu18.04默认安装完以后镜像是官方的,国内更新速度太慢,更新为阿里云或中科大等其他国内源,速度会明显提高,操作方法如下:
备份原文件:

cp /etc/apt/sources.list /etc/apt/sources.list_bak

将/etc/apt/sources.list文件内容替换为如下:(任意其一即可)
阿里云镜像源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

网易镜像源

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

清华镜像源

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

中科大镜像源

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

更新系统及软件

sudo apt-get update

sudo apt-get upgrade

后面在安装软件速度就很快了~.

192 MB的VPS上安装ss服务基于Ubuntu16.04

在内存只有192MB小鸡vps上安装ss服务,基于ubuntu16.04精简版,安装脚本命令如下:

apt-get update

pip install -U pip

pip3 install --upgrade pip

pip3 install shadowsocks

pip install --upgrade shadowsocks

pip3 install --upgrade shadowsocks
     
cat <<EOF>> /etc/shadowsocks.json
{
    "server":"vps ipadder",
    "local_address":"127.0.0.1",
    "local_port":8888,
    "port_password":{
         "9001":"password",
         "9002":"password"
    },
    "timeout":600,
    "method":"aes-256-cfb",
    "fast_open": false
}
EOF

/usr/local/bin/ssserver -c /etc/shadowsocks.json >> /ss.log 2>&1 &

---阅读剩余部分---

pip升级后出现"from pip import main" line 9问题的解决方法

在Ubuntu或CentOS中,升级了pip版本,再次使用pip 安装相关的包的时候就出现以下错误

Traceback (most recent call last): 
File “/usr/bin/pip”, line 9, in <module>
from pip import main

解决:pip文件在usr/bin目录下,cd进去,进行以下修改

from pip import main
if __name__ == '__main__':
    sys.exit(main())

换成下面的三行

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

然后问题就解决了;
pip3也是一样;

使用国内镜像源 提高pip安装更新速度

不论是使用 pip,还是 Pipenv、Poetry等工具,安装 Python 包的时候会默认从官方的 PyPI 源下载文件,速度比较慢。国内的一些公司和机构提供了 PyPI 镜像源(mirror source),你可以设置让这些工具从国内的镜像源安装 Python 包,以便提高下载速度。

官方 PyPI 源的 URL 为 https://pypi.org/simple (旧的 URL 为 https://pypi.python.org/simple

pip更换临时设置可以通过 -i 选项:

pip install -i https://mirrors.aliyun.com/pypi/simple/ flask

永久更换:
Windows系统:
首先在window的文件夹窗口输入 : %APPDATA%



---阅读剩余部分---

MySQL子查询参数说明

MySQL查询的五种子句

where子句(条件查询):按照“条件表达式”指定的条件进行查询。

group by子句(分组):按照“属性名”指定的字段进行分组。group by子句通常和count()、sum()等聚合函数一起使用。

having子句(筛选):有group by才能having子句,只有满足“条件表达式”中指定的条件的才能够输出。

order by子句(排序):按照“属性名”指定的字段进行排序。排序方式由“asc”和“desc”两个参数指出,默认是按照“asc”来排序,即升序。

limit(限制结果集)。

---阅读剩余部分---

Nginx 414 Request-URI Too Large报错解决方法

症状:前台客户端发送大量请求或发送的数据包太大的时候,nginx会报nginx 414 Request-URI Too Large错误,如下图
1.png
检查Log里面显示有大量报错

2019/04/09 15:03:32 [error] 21197#0: *90489 client intended to send too large body: 1470779 bytes, client: 124.74.25.254, server: zt-test.xxx.cn, request: "POST /cinema/salesman/save HTTP/1.1", host: "zt-test.xxx.cn:8080", referrer: "http://zt-test.xxx.cn:8080/index"
2019/04/09 15:22:37 [error] 21200#0: *90745 client intended to send too large body: 1376065 bytes, client: 114.86.94.252, server: zt-test.xxx.cn, request: "POST /cinema/salesman/save HTTP/1.1", host: "zt-test.xxx.cn:8080", referrer: "http://zt-test.xxx.cn:8080/index"
2019/04/10 09:08:46 [error] 21200#0: *91741 client intended to send too large body: 1470779 bytes, client: 124.74.25.254, server: zt-test.xxx.cn, request: "POST /cinema/salesman/save HTTP/1.1", host: "zt-test.xxx.cn:8080", referrer: "http://zt-test.xxx.cn:8080/index


---阅读剩余部分---

AWS镜像AMI制作

先在本地安装Oracle VM VirtualBox,安装好虚拟机(调整优化系统各个参数)此处不再赘述,IP设置为自动获取,最后关机导出,格式为“开放式虚拟化格式 1.0”,如下图,导出完以后上传到S3存储上;

---阅读剩余部分---

最新

分类

归档

评论

  • ice: 嗯,少了个cd进入目录·
  • peter: wget https...
  • Emerson: 写的好

其它