配置yum源

  1. wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
  2. rpm -ivh mysql57-community-release-el7-11.noarch.rpm
  3. yum makecache

安装mysql

  1. yum install mysql-community-server -y
  2. systemctl enable mysqld
  3. systemctl start mysqld
  4. mkdir /var/log/mysql
  5. chown -R mysql.mysql /var/log/mysql

获取mysql初始密码

  1. grep 'temporary password' /var/log/mysqld.log
  1. [root@template-centos7 src]# grep 'temporary password' /var/log/mysqld.log
  2. 2021-11-10T08:48:12.717987Z 1 [Note] A temporary password is generated for root@localhost: fp?GPt&wM2ij

配置文件

  1. [client]
  2. port = 3306
  3. socket = /var/log/mysql/mysql.sock
  4. #default-character-set = utf8
  5. [mysql]
  6. prompt=\\u@\\d>
  7. [mysqld]
  8. server-id = 2
  9. port = 3306
  10. bind-address = 0.0.0.0
  11. socket = /var/log/mysql/mysql.sock
  12. skip-name-resolve
  13. datadir = /data/mysql
  14. character-set-server = utf8_bin
  15. max_connections = 1000
  16. open_files_limit = 65535
  17. log-error = /var/log/mysql/error.log
  18. pid-file = /var/log/mysql/mysql.pid
  19. back_log = 256
  20. max_connect_errors = 256
  21. table_open_cache = 2048
  22. max_allowed_packet = 64M
  23. binlog_cache_size = 2M
  24. max_heap_table_size = 128M
  25. sort_buffer_size = 8M
  26. join_buffer_size = 8M
  27. thread_cache_size = 256
  28. #thread_concurrency = 8
  29. query_cache_size = 256M
  30. query_cache_limit = 2M
  31. thread_stack = 192K
  32. transaction_isolation = REPEATABLE-READ
  33. tmp_table_size = 64M
  34. expire_logs_days=30
  35. max_binlog_size = 512M
  36. slow_query_log = 0
  37. long_query_time = 0.5
  38. key_buffer_size = 256M
  39. read_buffer_size = 8M
  40. read_rnd_buffer_size = 8M
  41. bulk_insert_buffer_size = 64M
  42. myisam_sort_buffer_size = 128M
  43. myisam_max_sort_file_size = 10G
  44. myisam_repair_threads = 1
  45. explicit_defaults_for_timestamp=true
  46. log_timestamps=SYSTEM
  47. innodb_file_per_table=ON
  48. innodb_buffer_pool_size = 13G
  49. innodb_thread_concurrency = 16
  50. innodb_flush_log_at_trx_commit = 1
  51. innodb_log_buffer_size = 18M
  52. innodb_log_file_size = 512M
  53. innodb_open_files = 65535
  54. innodb_log_files_in_group = 2
  55. innodb_lock_wait_timeout = 120
  56. [mysqldump]
  57. quick
  58. max_allowed_packet = 64M
  59. [mysql]
  60. no-auto-rehash
  61. prompt=\\u@\\d>
  62. [myisamchk]
  63. key_buffer_size = 512M
  64. sort_buffer_size = 512M
  65. read_buffer = 8M
  66. write_buffer = 8M

修改密码

  1. # 第一次修改密码
  2. ALTER USER 'root'@'localhost' IDENTIFIED BY 'New_password1';
  3. # 之后修改密码
  4. update mysql.user set authentication_string=password('New_password1') where user='root' ;