配置文件路径为:
/etc/mysql/mysql.conf.d/mysqld.cnf
但更常用的配置文件路径是
/etc/mysql/my.cnf
1 打开配置文件
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
主要配置信息说明
port表示端口号,默认为3306 bind-address表示服务器绑定的ip,默认为127.0.0.1 datadir表示数据库保存路径,默认为/var/lib/mysql log_error表示错误日志,默认为/var/log/mysql/error.log
#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 192.168.3.67
mysqlx-bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size = 16M
# max_allowed_packet = 64M
# thread_stack = 256K
# thread_cache_size = -1
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
# max_connections = 151
# table_open_cache = 4000
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file = /var/log/mysql/query.log
# general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# 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
# binlog_expire_logs_seconds = 2592000
max_binlog_size = 100M
# binlog_do_db = include_database_name
# binlog_ignore_db = include_database_name
transaction-isolation=READ-COMMITTED
2 配置完成后重启mysql
service mysql restart
3 mysql8设置密码
sudo mysql_secure_installation
root的plugin下面是auth_socket,是不允许用密码登录的
select user,authentication_string,plugin,host from mysql.user;
可能密码太简单不符合
查看当前安全变量值,可用命令查看 validate_password 密码验证插件是否安装。
show variables like ‘validate_password%’;
validate_password_mixed_case_count大小写的最小个数。
validate_password_special_char_count 特殊字符的最小个数。
validate_password_dictionary_file 字典文件
要想在高版本使用简单的密码,需要做这样设置:
set global validate_password.policy=0; set global validate_password.length=3; set global validate_password.mixed_case_count=0; set global validate_password.number_count=3; set global validate_password.special_char_count=0;
alter user ‘root’@’localhost’ identified by ‘123456’; flush privileges; alter user ‘root’@’localhost’ identified with caching_sha2_password by ‘123456’; flush privileges;
4 新配置文件
以后配置文件统一用下面这个
/etc/mysql/my.cnf
# mysql下的是MySQL客户端的配置
[mysql]
# mysqld下的是MySQL服务端的配置
[mysqld]
user = mysql
port = 3306
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
# 数据库的数据保存的目录
datadir = /var/lib/mysql
# 允许连接的IP地址, 注释掉之后所有IP的机器都可以连接本MySQL服务端
# bind-address = 127.0.0.1
# 禁止MySQL客户端与服务器通过TCP/IP进行通信
# skip-networking
# 指定单个查询能够使用的缓冲区大小
key_buffer_size = 16M
# 服务器发送和接受的最大包长度
# max_allowed_packet = 64M
# 线程使用的堆大小. 此容量的内存在每次连接时被预留
# thread_stack = 256K
# 联合查询操作所能使用的缓冲区大小
# thread_cache_size = -1
# 指定myisam类型的表通过备份进行数据恢复
myisam-recover-options = BACKUP
# MySQL允许的最大连接数量, 若超过此数量, 新来的请求将会被存在堆栈中以等待某一连接释放资源
# max_connections = 151
# 通用日志
general_log_file = /var/log/mysql/mysql.log
general_log = 1
# 错误日志
log_error = /var/log/mysql/error.log
# 二进制日志(主从同步时要用)
log_bin = /var/log/mysql/mysql-bin.log
binlog_expire_logs_seconds = 864000 # 超过10天的binlog删除
max_binlog_size = 100M
# 本机的序号, 同一局域网内要唯一, 配置主从的关键
server-id = 1
# 事务隔离: MySQL默认采用的是REPEATABLE-READ
transaction-isolation=READ-COMMITTED
service mysql restart