MariaDB [(none)]> show grants for lyshark; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]>
查询指定权限: 查询lyshark用户的远程%权限,和本地localhost权限
MariaDB [(none)]> show grants for"lyshark"@"%"; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> show grants for"lyshark"@"localhost"; +----------------------------------------------------------------------------------------------------------------+ | Grants for lyshark@localhost | +----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'lyshark'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | +----------------------------------------------------------------------------------------------------------------+ 1 row inset (0.37 sec)
MariaDB [(none)]>
◆授予权限◆
创建用户并授权: 创建wang用户并给予%远程登陆的权限,并对所有数据库全部授权
MariaDB [(none)]> grant all on *.* to "wang"@"%" identified by "123"; Query OK, 0 rows affected (0.15 sec)
MariaDB [(none)]> show grants for"wang"@"%"; +--------------------------------------------------------------------------------------------------------------+ | Grants for wang@% | +--------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'wang'@'%' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | +--------------------------------------------------------------------------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> grant select on mysql.* to "wang1"@"localhost" identified by "123"; Query OK, 0 rows affected (0.36 sec)
MariaDB [(none)]> show grants for"wang1"@"localhost"; +--------------------------------------------------------------------------------------------------------------+ | Grants for wang1@localhost | +--------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wang1'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | | GRANT SELECT ON `mysql`.* TO 'wang1'@'localhost' | +--------------------------------------------------------------------------------------------------------------+ 2 rows inset (0.00 sec)
MariaDB [(none)]> grant select on mysql.* to "wang3"@"192.168.1.59" identified by "123"; Query OK, 0 rows affected (0.15 sec)
MariaDB [(none)]> show grants for"wang3"@"192.168.1.59"; +-----------------------------------------------------------------------------------------------------------------+ | Grants for wang3@192.168.1.59 | +-----------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'wang3'@'192.168.1.59' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' | | GRANT SELECT ON `mysql`.* TO 'wang3'@'192.168.1.59' | +-----------------------------------------------------------------------------------------------------------------+ 2 rows inset (0.50 sec)
MariaDB [(none)]>
创建用户并授权: 创建一个普通用户wang4,且仅有mysql库的(查)权限,密码为123
MariaDB [(none)]> grant usage,select on mysql.* to "wang4"@"localhost" identified by "123"; Query OK, 0 rows affected (0.35 sec)
只授权用户权限: 授权用户wang4,对所有数据库的全部权限,密码123
MariaDB [(none)]> grant all privileges on *.* to "wang4"@"localhost" identified by "123"; Query OK, 0 rows affected (0.36 sec)
只授权用户权限: 授权一个已存在账号允许远程登陆最大权限
MariaDB [(none)]> grant all on *.* to "root"@"%"; Query OK, 0 rows affected (0.07 sec)
◆收回权限◆
收回用户授权: 撤销lyshark用户,对所有数据库的远程%用户权限
MariaDB [(none)]> show grants for lyshark; +----------------------------------------------+ | Grants for lyshark@% | +----------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'lyshark'@'%' | +----------------------------------------------+ 1 row inset (0.00 sec)
MariaDB [(none)]> revoke all on *.* from "lyshark"@"%"; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show grants for lyshark; +-------------------------------------+ | Grants for lyshark@% | +-------------------------------------+ | GRANT USAGE ON *.* TO 'lyshark'@'%' | +-------------------------------------+ 1 row inset (0.00 sec)
收回用户授权: 撤销lyshark用户的远程登陆权限
MariaDB [(none)]> revoke create on *.* from "lyshark"@"%"; Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show global variables like "%read_only%"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | OFF | +---------------+-------+ 1 row inset (0.00 sec)
MariaDB [(none)]> set global read_only=1; #1是只读,0是读写 Query OK, 0 rows affected (0.08 sec)
MariaDB [(none)]> show global variables like "%read_only%"; #再次查询读写状态 +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | ON | +---------------+-------+ 1 row inset (0.00 sec)
[mysqld] log-bin="/tmp"#设置开启日志,也可不指定日志保存位置 expire_logs_days = 10 #设置日志自动清理天数 max_binlog_size = 100M #定义了单个文件的大小限制
2.添加完毕后,重启数据库进程,即可打开二进制日志啦.
[root@localhost~]# systemctl restart mariadb [root@localhost~]# mysql Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is2 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; mysqlbinlog: File 'mariadb-bin.000001' not found (Errcode: 2) DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
删除二进制日志:
1.我们可以手动删除二进制日志,通过使用reset master语句删除所有日志,SQL语句如下:
[root@localhost ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
[root@localhost ~]# systemctl restart mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like 'log_error'; +---------------+------------------------------+ | Variable_name | Value | +---------------+------------------------------+ | log_error | /var/log/mariadb/mariadb.log | +---------------+------------------------------+ 1 row inset (0.01 sec)
[root@localhost ~]# cat /var/log/mariadb/mariadb.log |head -n 10 181224 20:28:49 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 181224 20:28:49 [Note] /usr/libexec/mysqld (mysqld 5.5.60-MariaDB) starting as process 1622 ... 181224 20:28:49 InnoDB: The InnoDB memory heap is disabled 181224 20:28:49 InnoDB: Mutexes and rw_locks use GCC atomic builtins 181224 20:28:49 InnoDB: Compressed tables use zlib 1.2.7 181224 20:28:49 InnoDB: Using Linux native AIO 181224 20:28:50 InnoDB: Initializing buffer pool, size = 128.0M 181224 20:28:50 InnoDB: Completed initialization of buffer pool InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created!
删除错误日志:
[root@localhost~]# mysql Welcome to the MariaDB monitor. Commands endwith ; or \g. Your MariaDB connection id is3 Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;'or'\h'for help. Type '\c'to clear the current input statement.