资料来源于墨天轮
.cnf
/etc/mysql/my.cnf
[email protected]:~# mysql --help |grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf etc/mysql/my.cnf ~/.my.cnf
/etc/mysql/my.cnf
/etc/mysql/mysql.cnf
/etc/mysql/my.cnf
~/.my.cnf
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.!includedir /etc/mysql/conf.d/
#表示包含/etc/mysql/conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀
!includedir /etc/mysql/mysql.conf.d/
#表示包含/etc/mysql/mysql.conf.d/这个路径下面的配置文件,前提是必须以为.cnf为后缀
/usr/lib/mysql # 动态库文件(.so文件,so=shared object)
/usr/bin/mysql # mysql命令,安装的软件的命令,usr指Unix System Resource
/usr/share/mysql # mysql共享数据,主要是一些帮助文档
/etc/mysql # mysql配置文件目录
/etc/init.d/mysql # 服务管理脚本(启动,停止,关闭等)
/var/lib/mysql # 默认的数据文档存储目录
/var/log/mysql # mysql日志文件(查询语句记录,报错日志,慢查询日志等)
select user,host from mysql.user where length(authentication_string) = 0;
或
select user,host,authentication_string,password_lifetime,account_locked from mysql.user;
set password for 'user'@'host' = password('yourpassword');
set password for 'testtest'@'192.168.56.1' = password('testtest');
ALTER USER 'user'@'host' ACCOUNT LOCK;
mysql> show global variables like 'default_password_lifetime';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| default_password_lifetime | 0 |
+---------------------------+-------+
1 row in set (0.00 sec)
default_password_lifetime = 180
ALTER USER 'root'@'localhost' PASSWORD EXPIRE INTERVAL 180 DAY;
关于MySQL密码你应该知道的那些事 - cenalulu MySQL:密码加密方式 - xuejianbest
[mysqld]
plugin-load = "validate_password.so"
validate-password = FORCE_PLUS_PERMANENT
validate_password_length = 8
validate_password_policy = 1
validate_password_mixed_case_count = 1
validate_password_number_count = 1
validate_password_special_char_count = 1
validate-password = FORCE_PLUS_PERMANENT
FORCE_PLUS_PERMANENT
validate_password_policy
mysql> show variables like '%validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
安装和卸载插件 validate_password插件相关参数的介绍 MySql5.6使用validate password 插件加强密码强度的安装及使用方法 - wangmm0218
mysql> show variables like "%connection_control%";
+-------------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------------+-------+
| connection_control_failed_connections_threshold | 3 |
| connection_control_max_connection_delay | 86400 |
| connection_control_min_connection_delay | 1000 |
+-------------------------------------------------+-------+
3 rows in set (0.00 sec)
show global variables like 'interactive_timeout';
show global variables like 'wait_timeout';set global interactive_timeout=1800;
set global wait_timeout=1800;
interactive_timeout:交互式连接超时时间(mysql工具、mysqldump等)
wait_timeout:非交互式连接超时时间、默认的连接mysql api程序、jdbc连接数据库等
连接控制插件安装 MySQL安全插件:Connection-Control Plugins 的利与弊 - leonpenn MySQL 插件之 连接控制插件(Connection-Control) - ZhenXing_Yu MySQL连接超时相关的两个参数interactive_timeout和wait_timeout的区别和解释 - young5201314 MySQL参数max_connect_errors分析释疑 - 潇湘隐者 MySQL状态变量Aborted_connects与Aborted_clients浅析 -海东潮
validate-password = FORCE_PLUS_PERMANENT
FORCE_PLUS_PERMANENT
validate_password_policy
mysql> show variables like '%validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
安装和卸载插件 validate_password插件相关参数的介绍 MySql5.6使用validate password 插件加强密码强度的安装及使用方法 - wangmm0218
mysql> show variables like "%connection_control%";
+-------------------------------------------------+-------+
| Variable_name | Value |
+-------------------------------------------------+-------+
| connection_control_failed_connections_threshold | 3 |
| connection_control_max_connection_delay | 86400 |
| connection_control_min_connection_delay | 1000 |
+-------------------------------------------------+-------+
3 rows in set (0.00 sec)
show global variables like 'interactive_timeout';
show global variables like 'wait_timeout';set global interactive_timeout=1800;
set global wait_timeout=1800;
interactive_timeout:交互式连接超时时间(mysql工具、mysqldump等)
wait_timeout:非交互式连接超时时间、默认的连接mysql api程序、jdbc连接数据库等
连接控制插件安装 MySQL安全插件:Connection-Control Plugins 的利与弊 - leonpenn MySQL 插件之 连接控制插件(Connection-Control) - ZhenXing_Yu MySQL连接超时相关的两个参数interactive_timeout和wait_timeout的区别和解释 - young5201314 MySQL参数max_connect_errors分析释疑 - 潇湘隐者 MySQL状态变量Aborted_connects与Aborted_clients浅析 -海东潮
mysql> show variables like '%ssl';
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
+---------------+----------+
2 rows in set (0.01 sec)
select user,host from mysql.user;
MySQL SSL配置(mysql5.7和mysql5.6) - Yuki_xiong MYSQL SSL配置与使用 - 德莱華
GRANT ALL PRIVILEGES ON <databases-name>.* TO 'user'@'<ip>' IDENTIFIED BY '<password>' WITH GRANT OPTION;
FLUSH PRIVILEGES;
# 举例,给数据库用户teacher分配student数据库,只允许192.168.56.%网段远程连接并设置口令为Admin123。
GRANT ALL PRIVILEGES ON student.* TO 'teacher'@'192.168.56.%' IDENTIFIED BY 'Admin123' WITH GRANT OPTION;
FLUSH PRIVILEGES;
select user,host from mysql.user where account_locked='N' and host!='localhost';
drop user 'user'@'host';
mysql> show variables like "%connections";
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| max_connections | 100 |
| max_user_connections | 0 |
+----------------------+-------+
2 rows in set (0.01 sec)
[email protected]:~$ grep max_connections etc/mysql/mysql.conf.d/mysqld.cnf
max_connections = 100
MySQL参数最大连接数max_connections - paul_hch
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#通用日志,将所有到达MySQL Server的SQL语句记录下来
general_log_file = var/log/mysql/mysql.log
general_log = 1
log_timestamps = SYSTEM
#
# Error log - should be very few entries.
#错误日志,文件内容不会很多
log_error = var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#慢查询日志,记录SQL执行语句(执行时间超过2秒才会记录)
slow_query_log = 1
slow_query_log_file = var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#二进制日志
server-id = 1
log_bin = var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#Linux 检查NTP服务时间同步情况
ntpq -p -n
ntpstat
find -name ".mysql_history" | xargs
rm <your_path>/.mysql_history
ln -s dev/null <your_path>/.mysql_history
show variables like 'local_infile';
[mysqld]
local_infile = 0
select user,host,account_locked from mysql.user;
show grants for 'user'@'host';
select * from mysql.user where user='user' and host='host' \G;
SET GLOBAL default_password_lifetime = 180;
#设置全局变量及赋值。
INSTALL PLUGIN validate_password SONAME 'validate_password.so';
#安装插件,这里是安装配置密码复杂度策略的插件。
update user set password=password('123') where user='root' and host='localhost';
# mysql 5.7以下update mysql.user set authentication_string=PASSWORD('newpassword') where user='username' and host='localhost';
# mysql 5.7以上alter user 'root'@'localhost' identified by 'newpassword';
# mysql 8.0以上
侵权请私聊公众号删文
热文推荐