no comments yet
07 Dec 2019

centos7配置端口转发

#!/bin/bash
#开启系统路由模式功能
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
#运行这个命令会输出上面添加的那一行信息,意思是使内核修改生效
sysctl -p
#开启firewalld
systemctl start firewalld
#开启4650端口监听tcp请求
firewall-cmd --zone=public --add-port=4650/tcp --permanent
#设置IP地址伪装
firewall-cmd --add-masquerade --permanent
#设置端口映射
firewall-cmd --add-forward-port=port=4650:proto=tcp:toaddr=211.211.211.211:toport=3389 --permanent
firewall-cmd --add-masquerade --permanent
#重启firewall
firewall-cmd --reload

如果提示firewall-cmd: command not found错误,

yum install firewalld -y
no comments yet
25 Nov 2019

CentOS7 中文文件名乱码

一台CentOS7的server上有一些资料,想用脚本传到dropbox上去,其中一部分是中文目录/文件名,在CentOS7下不能正常显示,所以传输失败,查了下原因,在WIndows创建的的文件名中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码不一致所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码。
安装文件名转码工具convmv:

yum -y install convmv

对中文目录/文件转码:

convmv -f GBK -t UTF-8 --notest -r /home/test

/home/test --- 代表出现乱码所在的文件的目录

Read more

no comments yet
15 Nov 2019

MySQL查询某个字段中长度最大的记录

要从MySQL的某个字段中,找出长度最大的记录:

SELECT *
FROM 表名
WHERE LENGTH(
字段名 ) = (
SELECT MAX( LENGTH(
字段名 ) )
FROM 表名 )
no comments yet
14 Nov 2019

MySQL去除字段中的换行符回车符

执行以下SQL语句:

UPDATE card_bin SET  bank_name = REPLACE(REPLACE(bank_name, CHAR(10), ''), CHAR(13), '');

card_bin为目标表,bank_name为目标字段,CHAR(10)是换行符,CHAR(13)是回车符。

no comments yet
10 Nov 2019

mysql修改root用户密码

登录MySQL,

mysql> set password for root@localhost = password('新密码');

或者,update直接修改mysql库中的user表:

mysql> update user set password=password('888') where user='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)