配置文件路径为:

/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

  1. #
  2. # The MySQL database server configuration file.
  3. #
  4. # One can use all long options that the program supports.
  5. # Run program with --help to get a list of available options and with
  6. # --print-defaults to see which it would actually understand and use.
  7. #
  8. # For explanations see
  9. # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
  10. # Here is entries for some specific programs
  11. # The following values assume you have at least 32M ram
  12. [mysqld]
  13. #
  14. # * Basic Settings
  15. #
  16. user = mysql
  17. pid-file = /var/run/mysqld/mysqld.pid
  18. socket = /var/run/mysqld/mysqld.sock
  19. port = 3306
  20. datadir = /var/lib/mysql
  21. # If MySQL is running as a replication slave, this should be
  22. # changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
  23. # tmpdir = /tmp
  24. #
  25. # Instead of skip-networking the default is now to listen only on
  26. # localhost which is more compatible and is not less secure.
  27. bind-address = 192.168.3.67
  28. mysqlx-bind-address = 127.0.0.1
  29. #
  30. # * Fine Tuning
  31. #
  32. key_buffer_size = 16M
  33. # max_allowed_packet = 64M
  34. # thread_stack = 256K
  35. # thread_cache_size = -1
  36. # This replaces the startup script and checks MyISAM tables if needed
  37. # the first time they are touched
  38. myisam-recover-options = BACKUP
  39. # max_connections = 151
  40. # table_open_cache = 4000
  41. #
  42. # * Logging and Replication
  43. #
  44. # Both location gets rotated by the cronjob.
  45. #
  46. # Log all queries
  47. # Be aware that this log type is a performance killer.
  48. # general_log_file = /var/log/mysql/query.log
  49. # general_log = 1
  50. #
  51. # Error log - should be very few entries.
  52. #
  53. log_error = /var/log/mysql/error.log
  54. #
  55. # Here you can see queries with especially long duration
  56. # slow_query_log = 1
  57. # slow_query_log_file = /var/log/mysql/mysql-slow.log
  58. # long_query_time = 2
  59. # log-queries-not-using-indexes
  60. #
  61. # The following can be used as easy to replay backup logs or for replication.
  62. # note: if you are setting up a replication slave, see README.Debian about
  63. # other settings you may need to change.
  64. # server-id = 1
  65. # log_bin = /var/log/mysql/mysql-bin.log
  66. # binlog_expire_logs_seconds = 2592000
  67. max_binlog_size = 100M
  68. # binlog_do_db = include_database_name
  69. # binlog_ignore_db = include_database_name
  70. transaction-isolation=READ-COMMITTED

2 配置完成后重启mysql

service mysql restart

3 mysql8设置密码

sudo mysql_secure_installation

image.png
image.png
image.png
image.png
root的plugin下面是auth_socket,是不允许用密码登录的

select user,authentication_string,plugin,host from mysql.user;

image.png
可能密码太简单不符合
image.png
查看当前安全变量值,可用命令查看 validate_password 密码验证插件是否安装。

show variables like ‘validate_password%’;

image.png
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;

image.png

alter user ‘root’@’localhost’ identified by ‘123456’; flush privileges; alter user ‘root’@’localhost’ identified with caching_sha2_password by ‘123456’; flush privileges;

image.png

4 新配置文件

以后配置文件统一用下面这个

/etc/mysql/my.cnf

  1. # mysql下的是MySQL客户端的配置
  2. [mysql]
  3. # mysqld下的是MySQL服务端的配置
  4. [mysqld]
  5. user = mysql
  6. port = 3306
  7. pid-file = /var/run/mysqld/mysqld.pid
  8. socket = /var/run/mysqld/mysqld.sock
  9. # 数据库的数据保存的目录
  10. datadir = /var/lib/mysql
  11. # 允许连接的IP地址, 注释掉之后所有IP的机器都可以连接本MySQL服务端
  12. # bind-address = 127.0.0.1
  13. # 禁止MySQL客户端与服务器通过TCP/IP进行通信
  14. # skip-networking
  15. # 指定单个查询能够使用的缓冲区大小
  16. key_buffer_size = 16M
  17. # 服务器发送和接受的最大包长度
  18. # max_allowed_packet = 64M
  19. # 线程使用的堆大小. 此容量的内存在每次连接时被预留
  20. # thread_stack = 256K
  21. # 联合查询操作所能使用的缓冲区大小
  22. # thread_cache_size = -1
  23. # 指定myisam类型的表通过备份进行数据恢复
  24. myisam-recover-options = BACKUP
  25. # MySQL允许的最大连接数量, 若超过此数量, 新来的请求将会被存在堆栈中以等待某一连接释放资源
  26. # max_connections = 151
  27. # 通用日志
  28. general_log_file = /var/log/mysql/mysql.log
  29. general_log = 1
  30. # 错误日志
  31. log_error = /var/log/mysql/error.log
  32. # 二进制日志(主从同步时要用)
  33. log_bin = /var/log/mysql/mysql-bin.log
  34. binlog_expire_logs_seconds = 864000 # 超过10天的binlog删除
  35. max_binlog_size = 100M
  36. # 本机的序号, 同一局域网内要唯一, 配置主从的关键
  37. server-id = 1
  38. # 事务隔离: MySQL默认采用的是REPEATABLE-READ
  39. transaction-isolation=READ-COMMITTED

service mysql restart