Author Archives: Node

linux定时计划任务 自动删除目录下文件

运行系统;centos7.3 64 最小化安装

要实现定时删除某个目录下的所有文件需要用到linux的crontab命令,可以用shell脚本实现。例如删除/tmp下的所有缓存文件,操作如下:

[root@localhost ~]# vi /etc/init.d/delete.sh

按i并复制下面内容到delete.sh文件内,之后按shift+: 输入wq保存并退出。

#!/bin/bash
dir=/tmp //需要清空的目录名称
files=`ls ${dir}`
for file in $files
do
if [ -e ${dir}/${file} ];then
rm -f ${dir}/${file}
fi
done

然后给此脚本755权限,代码如下:

[root@localhost ~]# chmod 755 /etc/init.d/delete.sh

下面就使用crontab命令进行时间设定,例如,每天凌晨3点清除/tmp目录下的所有文件。运行以下命令会进入vim编辑界面。

[root@localhost ~]# crontab –e

粘贴以下代码;

0 3 * * * /etc/init.d/delete.sh

保存并退出,现在定时工作已经完成了,每天凌晨3点自动清空/tmp目录下的文件。

crontab –e的时间用法说明;

* * * * * /etc/init.d/delete.sh

分 时 日 月 周 命令
第1列*号表示分钟1-59 每分钟用*或者 */1表示
第2列*号表示小时0-23小时(0表示0点)
第3列*号表示日期1-31日
第4列*号表示月份1-12月
第5列*号表示每周,0-6(0表示星期天)
第6列是要运行的命令

例如每周3的晚上23:30运行该脚本,可以这样写:

30 23 * * 3 /etc/init.d/delete.sh

其他时间段也是如此。

linux centos7分区 格式化挂载磁盘

服务器安装centos的时候,通常linux系统分区默认为3个分区,主分区最多4个,其他可根据自己的需要挂载。

/ 根分区,通常10-100G左右(根据总磁盘大小情况)
/boot 系统操作分区 (100-500MB 足矣)
/swap 虚拟内存暂存分区(通常是内存的2倍)

如果有剩下的磁盘就保留,后期再挂载。安装完系统后就开始格式化剩下的分区,并挂载指派出来。

1、首先查看未指派的分区名称,有的不一样,我的分别是/dev/sda和/dev/sdb,sda是系统分区,sdb是存储数据分区。

# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00043041

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2、可以看到红色标注的是10G的数据磁盘,我们现在执行分区,代码如下:

# fdisk -S 56 /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x52d681d6.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help):【输入n回车,添加新分区,如果需要更多,请输入m回车看帮助】

Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):【输入p回车,P的意思是主分区】
Partition number (1-4, default 1):【输入数字1回车,分区数量】
First sector (2048-20971519, default 2048):【默认回车】
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):【默认回车】
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help):【输入wq保存】

The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3、分区完成。输入fdisk -l查看信息

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00043041

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x52d681d6

Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux

Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

4、可以查看/dev/sdb1已经被默认分区,现在开始格式化此分区。

注意:以下有几种常用磁盘格式,如果你想格式化ext3格式,代码如下;

# mkfs.ext3 /dev/sdb1

格式化ext4格式,代码如下;

# mkfs.ext4 /dev/sdb1

我这里采用的是xfs磁盘格式;代码如下;

# mkfs.xfs -f /dev/sdb1

meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

5、已经格式化成功。将磁盘挂载信息写入到系统配置文件中,不然开机不会自动挂载,代码如下;

# echo ‘/dev/sdb1 /www xfs defaults 0 0’ >> /etc/fstab
# mkdir /www //新建挂载目录
# mount -a //挂载磁盘
# df -h //查看挂载是否成功

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 8.0G 3.1G 5.0G 39% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 916M 0 916M 0% /dev/shm
tmpfs 916M 8.3M 908M 1% /run
tmpfs 916M 0 916M 0% /sys/fs/cgroup
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/sdb1 10G 33M 10G 1% /www

6、可以看到www目录已经挂载成功。

扩展阅读,fdisk -S 56 /dev/sdb的时候输入m有帮助信息,下面就列举说明:

a、toggle a bootable flag //切换一个可启动的标志
b、 edit bsd disklabel //编辑bsd disklabel
c、 toggle the dos compatibility flag //切换dos兼容性模式
d、 delete a partition //删除一个分区
g、 create a new empty GPT partition table //创建一个新的空GPT分区表
G 、create an IRIX (SGI) partition table //创建一个IRIX(SGI)分区表
l 、list known partition types //列出已知的分区类型
m、 print this menu //打印此菜单
n、 add a new partition //添加一个新的分区
o、 create a new empty DOS partition table //创建一个新的空DOS分区表
p、 print the partition table //打印分区表
q、 quit without saving changes //退出而不保存更改
s、 create a new empty Sun disklabel //创建一个新的空的Sun磁盘标签
t、 change a partition’s system id //更改分区的系统ID
u、 change display/entry units //更改显示/输入单位
v、 verify the partition table //验证分区表
w、 write table to disk and exit //将表写入磁盘保存并退出
x、extra functionality (experts only) //高级功能(仅限专家)

linux Nginx1.12.0平滑升级到新版本nginx-1.13.3

本篇演示生产环境:Centos7.3 64位 最小化安装版。

1.查看当前Nginx版本信息。代码如下:

# /usr/local/nginx/sbin/nginx -V
 nginx version: nginx/1.12.0
 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
 built with OpenSSL 1.0.1e-fips 11 Feb 2013
 TLS SNI support enabled
 configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-pcre --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-mail --with-threads --with-mail_ssl_module --with-stream_ssl_module

2.下载nginx-1.13.3版本到/usr/local/下,解压并进入解压后的目录。代码如下:

 # cd /usr/local/
 # wget //nginx.org/download/nginx-1.13.3.tar.gz
 # wget //www.openssl.org/source/openssl-1.1.0e.tar.gz //下载最新openssl
 # tar zxvf openssl-1.1.0e.tar.gz //解压文件
 # tar zxvf nginx-1.13.3.tar.gz
 # cd nginx-1.13.3

3.查看nginx版本的时候,configure后面有一大串模块,这也是你第一次安装nginx时所指定的模块,升级的时候也要同时指定,也可以添加其他模块。代码如下:

./configure \
 --prefix=/usr/local/nginx \
 --user=www \
 --group=www \
 --with-pcre \
 --with-openssl=/tmp/openssl-1.1.0e \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-http_realip_module \
 --with-http_addition_module \
 --with-http_sub_module \
 --with-http_dav_module \
 --with-http_flv_module \
 --with-http_mp4_module \
 --with-http_gunzip_module \
 --with-http_gzip_static_module \
 --with-http_random_index_module \
 --with-http_secure_link_module \
 --with-http_stub_status_module \
 --with-http_auth_request_module \
 --with-http_image_filter_module \
 --with-mail \
 --with-threads \
 --with-mail_ssl_module \
 --with-stream_ssl_module \
 # make

4.注意:make完以后,执行下面代码。不需要执行make install,否则会覆盖安装,nginx服务会出现各种问题。

不中断nginx web服务器的正常运行称之为平滑升级,先重命名之前的nginx二进制文件。代码如下:

# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

拷贝刚编译新生产的Nginx二进制文件到/usr/local/nginx/sbin/目录;代码如下:

# cp /usr/local/nginx-1.13.3/objs/nginx /usr/local/nginx/sbin/

5.开始执行升级命令。代码如下:

# cd /usr/local/nginx-1.13.3
 # make upgrade
 /usr/local/nginx/sbin/nginx -t
 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
 nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
 kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
 sleep 1
 test -f /usr/local/nginx/logs/nginx.pid.oldbin
 kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

6.再次查看nginx升级后的版本信息。代码如下:

# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.13.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.1.0e 16 Feb 2017
TLS SNI support enabled

可以看到已经成功升级到1.13.3,本文教程可用于生产环境当中。希望能帮到大家。转载请注明!

linux centos7系统tar文件压缩打包命令

实验环境:Centos7.* 64位,最小化安装版。长时间不解压缩,命令就会忘记,给自己留个记录,没事来看看。

打包成tar.gz格式压缩包

# tar -zcvf renwolesshel.tar.gz /renwolesshel

解压tar.gz格式压缩包

# tar zxvf renwolesshel.tar.gz

打包成tar.bz2格式压缩包

# tar -jcvf renwolesshel.tar.bz2 /renwolesshel

解压tar.bz2格式的压缩包

# tar jxvf renwolesshel.tar.bz2

压缩成zip格式

# zip -q -r renwolesshel.zip renwolesshel/

解压zip格式的压缩包

# unzip renwolesshel.zip

暂时先这些吧,后期遇到了再添加。

linux Centos7 ssh、sftp、scp命令远程传输文件

以下实验数据都是手工亲测,非拷贝而来,所以真实可靠,也是我在工作当中经常用到的一些命令,分享出来,大家一块学习。
系统操作环境Centos7.3 64 *2,两台机器都在公网IP地址分别是

A:223.5.5.5
B:223.6.6.6

一、sftp是一个交互式文件传输程式。它类似于ftp传输协议,属于ssh, 但它进行加密传输,相对FTP来讲有更高的安全性。

sftp用法

如果有服务器的端口不是默认的22,请在sftp后面加-P 端口号 即可。

# sftp root@223.6.6.6
The authenticity of host ‘223.6.6.6 (223.6.6.6)’ can’t be established.
ECDSA key fingerprint is SHA256:Hl/dKTFzL4lOlF8DIG5itaV4OAsZunC2AWlFGLjLfsg.
Are you sure you want to continue connecting (yes/no)? yes【输入yes回车】
Warning: Permanently added ‘223.6.6.6’ (ECDSA) to the list of known hosts.
root@223.6.6.6’s password:【输入223.6.6.6的root密码并回车】
Connected to 223.6.6.6.
sftp>

将223.6.6.6服务器文件下载到223.5.5.5的home目录;

sftp> get /var/www/renwole.txt /home/

将223.5.5.5服务器文件上传到223.6.6.6服务器的mnt目录;

sftp> put /home/renwole.txt /mnt/

你如果不知道远程主机的目录是什么样, ls命令可以列出223.6.6.6服务器的当前目录列表。例如:

sftp> ls //和查看本地操作命令一样
sftp> pwd //查询223.6.6.6的当前工作目录

改变路径可以用cd ,改变本机路径可以用 cd.. 例如;

sftp> cd

如果用于修改服务器文件,可以使用ssh连接,例如:

# ssh root@223.6.6.6
root@223.6.6.6’s password:【输入B服务器密码回车进入内部】

如果想退出,例如:

# exit //退出机器,返回你原始机器界面。

二、scp具有和ssh一样的验证机制,从而可以实现2台机器安全的远程拷贝文件。

scp可以概括为:

scp -P 端口 文件路径 用户名@主机地址:远程目录

如果想拷贝本地文件到另外一台ssh终端,可以使用以下命令;

# scp /renwole/mariadb.tar.gz root@223.6.6.6:/renwole123/
root@223.6.6.6’s password:【输入密码回车】
mariadb.tar.gz  8%  37MB  1.3MB/s  05:29  ETA

如果你反过来操作,把远程主机的文件拷贝到当前系统,操作命令以下;

# scp root@223.6.6.6:/renwole123/mariadb.tar.gz /renwole

如果你想拷贝文件夹以及文件夹内的所有文件,就加参数 -r 如果你的端口号不是22,那么需要在scp后加个 -P (区分大小写)端口号。建议加-C选项,因为这样可以启用SSH的压缩功能;传输速度更快,例如

# scp -P 6632 -C /renwole/mariadb root@223.6.6.6:/renwole123/

其实我个人建议使用scp,速度快,稳定,安全。

Linux centos7 SSH登录慢的解决方法

我们在安装linux系统的时候都没有关闭一个服务,导致登陆SSH时 输入完用户名后要等一会才能输入密码,经总结下面方案可解决此问题。

修改sshd_config以下两处,重启ssh即可。

# vi /etc/ssh/sshd_config
GSSAPIAuthentication no
UseDNS no

重启ssh

# systemctl restart sshd

以上能完美解决。

linux centos7清除系统日志、历史记录、登录信息

平时不管是web还是系统产生的日志都可能导致洗盘爆满,所以我在这里分享一些基本常用清理linux日志的方法。

# echo > /var/log/wtmp //清除用户登录记录
# echo > /var/log/btmp //清除尝试登录记录
# echo>/var/log/lastlog //清除最近登录信息
# echo > /var/log/secure //登录信息
# echo > /var/log/messages
# echo>/var/log/syslog //记录系统日志的服务
# echo>/var/log/xferlog
# echo>/var/log/auth.log
# echo>/var/log/user.log
# cat /dev/null > /var/adm/sylog
# cat /dev/null > /var/log/maillog
# cat /dev/null > /var/log/openwebmail.log
# cat /dev/null > /var/log/mail.info
# echo>/var/run/utmp

清除操作过的命令记录

# echo > .bash_history //清除保存的用户操作历史记录
# history -cw //清除所有历史

linux Centos7默认firewalld防火墙使用命令

Centos7默认的firewalld防火墙说实话真不好用,不如使用iptables。但一物的存在是有它的道理,比如在高级功能方面iptables就要次于firewalld防火墙,所以建议大家还是要追随主流,现在开源产品相对过去的版本更新很快,所以要跟得上脚步,特别是对于运维人员来讲。下面是我平时在生产环境当中维护机器常用到的,大家可以参考下。

基本操作;

 # systemctl start firewalld //启动
 # systemctl status firewalld //状态
 # systemctl disable firewalld //禁用
 # systemctl stop firewalld //停止

systemctl在centos7中必不可缺少的管理工具,它具备service和chkconfig的所有功能;

 # systemctl start firewalld.service //启动某个服务
 # systemctl stop firewalld.service //关闭某个服务
 # systemctl restart firewalld.service //重启某个服务
 # systemctl status firewalld.service //显示某个服务的状态
 # systemctl enable firewalld.service //开机时随机自启动
 # systemctl disable firewalld.service //禁止开机启动
 # systemctl is-enabled firewalld.service //查看是否开机启动
 # systemctl list-unit-files|grep enabled //查看已经启动的服列表
 # systemctl --failed //查看启动失败的服务列表

基本配置firewalld-cmd;

 # firewall-cmd --version //查看防火墙版本
 # firewall-cmd --help //查看命令操作帮助
 # firewall-cmd --state //显示当前状态
 # firewall-cmd --zone=public --list-ports //查看所有打开运行的端口
 # firewall-cmd --reload //不重启立即加载
 # firewall-cmd --list-all-zones | more //查看区域信息情况
 # firewall-cmd --get-zone-of-interface=eth0 //查看指定接口所属区域
 # firewall-cmd --panic-on //拒绝所有包
 # firewall-cmd --panic-off //取消拒绝状态
 # firewall-cmd --query-panic //查看是否拒绝

举个例子,如何打开一个端口,例如3306;

 # firewall-cmd --zone=public --add-port=3306/tcp --permanent //添加3306端口(--permanent)永久生效,没有此参数重启后失效
 # firewall-cmd --reload //不重启立即加载
 # firewall-cmd --zone= public --query-port=3306/tcp //查看加入3306端口状态
 # firewall-cmd --zone= public --remove-port=3306/tcp --permanent //删除刚刚加入的防火墙规则3306
 # firewall-cmd --permanent --remove-icmp-block=echo-request //删除禁ping
 # firewall-cmd --permanent --add-icmp-block=echo-request //开启禁ping
 # firewall-cmd --get-service //查看已被允许的信息

具体的规则管理,可以使用 firewall-cmd,具体的使用方法可以

 # firewall-cmd --help

firewall-cmd高级功能可以到官方资料库了解更多信息。

//fedoraproject.org/wiki/FirewallD/zh-cn
//access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html

//www.ibm.com/developerworks/cn/linux/1507_caojh/

注意:以上操作方法以及命令并不适用于Centos7以下版本,除你在其他linux发行版单独安装firewall的。

linux MariaDB(MySQL)数据库更改用户权限

平时维护MariaDB(MySQL)数据库服务器,难免会用到一些常用的命令,MariaDB数据库长时间不出问题,有些sql语句就会忘记,之前也没有记载,今天没事就记录下,也共享给大家一块看看,有不足之处还望谅解。

本文操作适用于MariaDB所有版本,适用于MySQL5.2以上版本
本文生产环境Centos7.3 64位 ,MariaDB server 10.2.5

MariaDB 赋予用户权限命令的简单格式可概括为:

grant 权限 on 数据库对象 to 用户;

# mysql -u root -p //登录数据库
 Enter password:
 MariaDB [(none)]> show databases; //查看当前数据库中所有数据库
 MariaDB [(none)]> create database renwole; //新建数据库名为“renwole”
 MariaDB [renwoleBD]> show tables; //显示某个数据库中的表文件
 MariaDB [(none)]> select version(),current_date; //查看数据库版本和当前日期
 MariaDB [(none)]> drop database renwole; //删除renwole数据库
 MariaDB [renwoleDB]> desc 表名称; //查看数据库表结构
 MariaDB [(none)]> show variables like '%dir%'; //查看数据库存储路径
 MariaDB [(none)]> show grants; 查看当前用户权限
 MariaDB [(none)]> show grants for root@'localhost'; //查看用户权限

下面就MariaDB数据库实例讲解,例如:

创建添加一个renwole用户,密码为renwole123

# mysql -u root -p //登录数据库
 Enter password:
 MariaDB [(none)]> insert into mysql.user(Host,User,Password) values("localhost","renwole",password("renwole123"));

新建一个renwoleDB数据库,并授权用户renwole拥有该数据库的所有权限。

MariaDB [(none)]> create database renwoleDB; //新建
 MariaDB [(none)]> grant all privileges on renwoleDB.* to renwole@% identified by 'renwole123'; //授权,关键字 “privileges” 可以省略。
 MariaDB [(none)]> flush privileges; //刷新用户权限

如果想给一个用户查询、插入、更新、删除数据库中的所有表数据权利,可以这样来写:

MariaDB [(none)]> grant select on on renwoleDB.* to renwole@’%’ //查询
 MariaDB [(none)]> grant insert on on renwoleDB.* to renwole@’%’ //插入
 MariaDB [(none)]> grant update on on renwoleDB.* to renwole@’%’ //更新
 MariaDB [(none)]> grant delete on on renwoleDB.* to renwole@’%’ //删除

或者,用一个语句命令替代:

MariaDB [(none)]> grant select,insert,delete,update on renwoleDB.* to renwole@’%’ identified by 'renwole123';

如果想查看所有Mysql用户的权限,代码如下;

MariaDB [(none)]> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

如果想删除一个用户及权限,可以这样写;

MariaDB [(none)]> drop user renwole@localhost;

如果想修改一个用户密码;

MariaDB [(none)]> update mysql.user set password=password('New-password') where User="renwole" and Host="%";
 MariaDB [(none)]> flush privileges;

添加高级root用户整个mysql服务器权限

grant all on *.* to root@'%' identified by 'Password';

注意:【identified by】这个句子可以顺带设置密码,如果不指定该用户口令不变。

撤销已经赋予给MariaDB用户的权限。
revoke 跟 grant 的语法相似,只需要把关键字 “to” 换成 “from” 即可,例如:

grant all on *.* to renwole@%;
 revoke all on *.* from renwole@%;

MariaDB数据库的 grant、revoke 用户权限注意事项;grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“,例如:

MariaDB [(none)]> grant select on renwoleDB.* to renwole@% with grant option;

这个特性一般用不到。实际中,数据库权限最好由root用户来统一管理。

注意:有时候renwole@’%’授权任意主机连接的时候需要加单引号,但有时又不需要。

linux centos7.3修改、破解mariadb(MySQL)数据库root密码

修改mysql密码有多种方案下面介绍2个

方案一

 # /usr/local/mysql/bin/mysqladmin -uroot -p password "New-password"
 Enter password: 【输入原有密码】 //输入后回车密码就修改成了New-password

方案二

 # mysql -uroot -p //回车登录mysql系统
 Enter password: 【输入原来的密码】

 MariaDB [(none)]> use mysql; //进入mysql数据库
 MariaDB [(none)]> update user set password=passworD("New-password") where user='root';
 MariaDB [(none)]> flush privileges; //刷新数据库
 MariaDB [(none)]> exit; //退出

修改完成!
如果你不记得之前的老密码,那么只能尝试破解,破解方案以下:
前置条件:必须拥有服务器最高管理员(root)权限。

 # systemctl stop mysql
 # /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

“&” 表示在后台运行,若不再后台运行,就再打开一个终端。

 # mysql
 MariaDB [(none)]> use mysql;
 MariaDB [(none)]> UPDATE user SET password=password("New-password") WHERE user='root';
 MariaDB [(none)]> flush privileges;
 MariaDB [(none)]> exit;

破解完成!