当前位置:   article > 正文

centos 7 安装 mysql 8_centos mysql环境变量

centos mysql环境变量

null




前言

      centos 7 安装 mysql 8 ,安装包直接在mysql官网下载,无需登录




一、linux设置

1.关闭防火墙

      检查防火墙状态
          systemctl status firewalld.service
      暂时关闭防火墙,下次启动时防火墙仍随系统启动而启动
          systemctl stop firewalld.service
      彻底永久关闭防火墙
           systemctl disable firewalld.service

      关闭SELINUX防火墙!
           vi /etc/selinux/config
      将内容
            SELINUX=enforcing
       更改为
            SELINUX=disabled

2.添加主机名 

        查看IP地址 : ifconfig -a / ip a
        查看主机名 : hostname
        然后修改/etc/hosts文件:
        vi /etc/hosts

        添加内容:ip 主机名

3.检查删除是否有安装过mysql

        CENTOS7: rpm -qa |grep mariadb

        rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps 

4.添加环境变量

  1. vim /etc/profile
  2. export MYSQL_HOME="/usr/local/mysql"
  3. export PATH="$PATH:$MYSQL_HOME/bin"



二、安装mysql



1.创建目录,用户组及用户

  1. mkdir -p /usr/local/mysql
  2. mkdir -p /data/mysql_data
  3. mkdir -p /data/mysql_log
  4. mkdir -p /data/log_bin
  5. mkdir -p /data/log_redo
  6. mkdir -p /data/log_relay
  7. mkdir -p /data/tmp
  8. groupadd mysql
  9. useradd -g mysql mysql
  10. chown -R mysql.mysql /data/mysql_data /data/mysql_log /data/log_bin /data/log_redo/ /data/log_relay /data/tmp
  11. chown -R mysql.mysql /usr/local/mysql



2.创建my.cnf文件

将隔离级别修改为读已提交(其它主流数据库默认隔离级别),可以提高并发度。

  1. [mysqld]
  2. # GENERAL #
  3. user = mysql
  4. collation_server=utf8mb4_general_ci
  5. character_set_server=utf8mb4
  6. default_storage_engine = InnoDB
  7. server_id = 1
  8. socket = /data/mysql_data/mysql.sock
  9. pid-file = /data/mysql_data/mysql.pid
  10. port = 3306
  11. transaction-isolation = READ-COMMITTED
  12. lower_case_table_names = 1
  13. sql_generate_invisible_primary_key = on
  14. # SAFETY #
  15. max_allowed_packet = 1G
  16. max_connect_errors = 1000000
  17. max_connections=3000
  18. max_user_connections=2800
  19. open_files_limit=65535
  20. skip_name_resolve=ON
  21. # DATA STORAGE #
  22. datadir = /data/mysql_data
  23. tmpdir = /data/tmp
  24. # BINARY LOGGING #
  25. binlog-ignore-db=mysql,information_schema,sys,performance_schema
  26. binlog_format = ROW
  27. log_bin = /data/log_bin/mysql_bin_3306
  28. binlog_expire_logs_seconds=1269600
  29. sync_binlog = 1
  30. max_binlog_size = 512M
  31. # CACHES AND LIMITS #
  32. tmp_table_size = 16M
  33. max_heap_table_size = 32M
  34. thread_cache_size = 64
  35. table_definition_cache = 4096
  36. table_open_cache = 4096
  37. # INNODB #
  38. #innodb_data_home_dir = /data/mysql_data/ibdata/
  39. innodb_data_file_path = ibdata1:128M;ibdata2:10M:autoextend
  40. innodb_flush_method = O_DIRECT
  41. innodb_lock_wait_timeout = 50
  42. innodb_flush_log_at_trx_commit = 1
  43. innodb_file_per_table = ON
  44. innodb_buffer_pool_instances = 8
  45. innodb_buffer_pool_size = 8G
  46. # repl #
  47. #rpl_semi_sync_master_enabled=1
  48. #rpl_semi_sync_master_timeout=1000
  49. gtid_mode=on
  50. enforce-gtid-consistency=1
  51. # REDOLOG #
  52. innodb_log_group_home_dir = /data/log_redo/
  53. innodb_log_buffer_size=67108864
  54. #innodb_log_file_size=256M
  55. #innodb_log_files_in_group=4
  56. innodb_redo_log_capacity=20m
  57. # LOGGING #
  58. log_error = /data/mysql_log/mysql_error_3306.log
  59. log_queries_not_using_indexes=0
  60. slow_query_log = 1
  61. long_query_time = 10
  62. log_slow_admin_statements=1
  63. slow_query_log_file = /data/mysql_log/mysql_slow_3306.log
  64. # RELAYLOG #
  65. relay_log = /data/log_relay/relaylog
  66. relay_log_index = /data/log_relay/relay.index
  67. # SLAVE #
  68. replica_load_tmpdir=/data/tmp
  69. [client]
  70. default_character_set=utf8mb4
  71. socket = /data/mysql_data/mysql.sock

3.配置系统服务

  1. cp -af /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  2. #############################################
  3. vi /etc/init.d/mysqld
  4. 修改两处位置:
  5. basedir=/usr/local/mysql
  6. datadir=/data/mysql_data
  7. #############################################

4.初始化数据库

  1. cd /usr/local/mysql/bin
  2. ./mysqld --initialize --lower-case-table-names=1 --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

5.启动数据库及登录

  1. service mysqld start
  2. mysql -uroot -p --然后这里出现Enter password:的时候直接按回车即可
  3. cat /data/mysql_log/mysql_error_3306.log|grep password可以找到初始密码
  4. 登录之后修改初始密码:
  5. alter user user() identified by '123456';

至此安装完毕

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/542081
推荐阅读
相关标签
  

闽ICP备14008679号