我们品牌 我们浪科做的是品牌服务,所以客户放心! |
我们服务 我们提供7x24小时在线服务,所以客户满意! |
我们价格 我们拥有行业里的最低价格,所以性价比最好! |
我们专业 我们做服务器托管租用10年,所以我们专业! |
以--skip-symbolic-links选项启动数据库:禁止在创建索引和创建表的时候,将索引文件和数据文件链接到其他文件。
bash drop database if exists ${dbname};
bash drop user ''
set password for <user>@<hostname> = password('<yourpassword>')
mysql> create user testuser;ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> CREATE USER 'test'@'localhost' IDENTIFIED BY '123456';ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> grant all privileges on *.* to testuser@"%" Identified by "123456";ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> use mysql; update user set password =PASSWORD('123456') where user ='system';Database changedERROR 1819 (HY000): Your password does not satisfy the current policy requirements
自问: 使用insert能够绕过 !?
mysql> insert into user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject)values('%','testuser','123456','BLOB','BLOB','BLOB');Query OK, 1 row affected (0.00 sec)
自答:
. insert直接插入的123456虽然可以插入成功但表中保存的应是加密后的内容,不能用123456进行登录;
. 使用PASSWORD('123456'),PASSWORD方法会进行校验,校验通过情况下insert方式(insert后记得flush privileges;)添加用户有效!
. 补充:即便使用UPPER(SHA1(UNHEX(SHA1('123456')))) ,插入其加密之后的值,也不能使用“123456”进行登录。
mysql> insert into user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject)values('%','testuser',PASSWORD('123456'),'BOLOB','BLOB','BLOB');ERROR 1819 (HY000): Your password does not satisfy the current policy requirementsmysql> update user set password=UPPER(SHA1(UNHEX(SHA1('123456')))) where user='testuser';...mysql> select user,host,password from user;+-------------+-----------+-------------------------------------------+| user| host| password|+-------------+-----------+-------------------------------------------+| root| 127.0.0.1 | *936A04AEF6CF3742E2F327C1970D875C588546F2 || testuser| % | 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|| system| % | *197D257ACCF6E52954DAA9A406D6B58EA95FCF45|+-------------+-----------+-------------------------------------------+# mysql -utestuser -p123456Warning: Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: YES)
Mysql提供的用户权限参考:Permissible Privileges for GRANT and REVOKE
mysql.user表只有管理员(root)用户才能操作
说明:实际应用中,有修改mysql.user的用户都算超级用户,都禁止远程连接数据库。
【mysql用户权限管理体系】
mysql.user表:记录用户的全局操作权限。GRANT ALL ON .和REVOKE ALL ON .
mysql.db表:记录用户对指定数据库的操作权限。 GRANT ALL ON db_name.和REVOKE ALL ON db_name.
mysql.talbes_priv表: 记录用户对指定表的操作权限。 GRANT ALL ON db_name.tbl_name和REVOKE ALL ON db_name.tbl_name
mysql.columns_priv表: 记录用户对表中具体列的操作权限。
注意: user表中没有相应的操作权限时,才会继续检查对应的数据库或表是否有操作权限。
以下权限只能赋予超级用户(root):
Shutdown_priv、Process_priv、File_priv、Grant_priv、Reload_priv、Super_priv 、Create_user_priv 、Repl_slave_privbash update mysql.user set Shutdown_priv='N',Process_priv='N',File_priv='N',Grant_priv='N',Reload_priv='N',Super_priv ='N',Create_user_priv ='N',Repl_slave_priv='N' where mysql.user.User!='root';
遗留:多实例情况下用户 multi_admin 也算管理员用户? 和root用户拥有一样的权限?
更改MySQL root用户的名字bash update mysql.user set user='<your_account>' where user='root' flush privileges
bash [mysqld] bind-address=<’ServerIP’>
bash 验证: select count(*) from mysql.user where Super_priv = 'Y' and host not in ('localhost','127.0.0.1','::1')
bash [mysqld] wait_timeout、interactive_timeout、slave-net-timeout
防暴力破解
Installing Connection Control Plugins
修改my.cnf配置文件:plugin-load-add="connection_control.so"connection-control=FORCE_PLUS_PERMANENTconnection-control-failed-login-attempts=FORCE_PLUS_PERMANENTconnection-control-failed-connections-threshold=3connection-control-min-connection-delay=1000connection-control-max-connection-delay=2147483647
扩展
确保对所有远端用户均设置了ssl_type参数
```bash
GRANT USAGE ON . TO
验证:
SELECT user, host, ssl_type FROM mysql.user WHERE NOT HOST IN ('::1', '127.0.0.1', 'localhost');
```
注意:服务端、客户端都需要配置SSL证书!
bash usermod -s /sbin/nologin mysql
bash rm <your_path>/.mysql_history ln -s /dev/null <your_path>/.mysql_history sed -i '$a readonly MYSQL_HISTFILE=/dev/null' /etc/profile
bash #chmod 700 <data_dir Value> #chown mysql:mysql <data_dir Value> #chmod 600 <data_dir Value>/* #chown mysql:mysql <data_dir Value>/*
错误日志(log_error):
记录了MySQL的启停和运行过程。——有问题首先看这个文件。
'log_error=/opt/mysql/data/aaa.err'
二进制日志(log_bin):
记录了对数据库执行更改的所有操作。
作用:数据恢复、复制、日志审计(如判断有无注入攻击)。log_bin [=name] # 默认关闭,需要配置此参数开启。不指定name默认文件名为'主机名.日志序号'。
备注:bin_log.00001即是二进制日志,bin_log.index为索引文件。二进制日志可使用自带的mysqlbinlog工具查看。
慢查询日志(slow_query_log_file):
记录运行慢的sql,帮助进行sql优化。slow_query_log=1 # 默认关闭,1启用,0禁用 [log_slow_queries] slow_query_log_file=slow.log # 指定文件路径和名字;默认值是'主机名-slow.log',位于datadir目录 long_query_time=3 # 执行时间超过设置阈值(s)的sql语句会被记录在slow_query_log_file中 log_output=FILE,TABLE # 指定慢查询的输出方式,动态参数。 FILE:慢查询日志;TABLE:mysql.slow_log表
Tips: 可以借助mysqldumpslow命令帮助分析慢查询日志。
查询日志(general_log_file)
记录了所有对数据库请求的信息。general_log=1 # 默认关闭,配置此参数开启查询日志。 general_log_file=/opt/mysql/data/general.log
按照log=/opt/mysql/data/xxx.log 配置,mysql服务启动失败。
可以动态开启:mysql>set global general_log_file='/tmp/general.log'; mysql>set global general_log=on; mysql>set global general_log=off;
与slow_log一样,可以将查询日志放入mysql.general_log表中。
bash #chmod 600 /xxx/my.cnf #chown mysql:mysql /xxx/my.cnf
show variables where variable_name = 'plugin_dir';
bash #chmod 500 <plugin_dir Value> #chown mysql:mysql <plugin_dir Value> #chmod 400 <plugin_dir Value>/* #chown mysql:mysql <plugin_dir Value>/*
bash show variables like 'ssl%';
浪科数据始于2003年,2005年已经工信部IDC/ICP/ISP认证企业,一直专注于IDC数据中心和云计算数据中心业务,目前全覆盖互联网+业务,不断满足用户的需求,提供深圳服务器租用,深圳服务器托管,深圳云主机,深圳云服务器,大带宽租用,高防服务器,企业建站,微信小程序等产品,全天候给您服务!
|