时间:2021-07-01 10:21:17 帮助过:16人阅读
①安装环境准备:
Centos8 配置1核2G
MySQL 版本:mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz
②安装步骤
1:解压mysql压缩包到指定目录
tar zxvf mysql-5.7.32-linux-glibc2.12-x86_64.tar.gz -C /usr/local
2:添加用户
groupadd mysql
useradd -r -g mysql -s /bin/flase mysql
3:创建数据目录
mkdir /opt/mysql
4:授权数据目录所属用户和组
chown mysql:mysql -R /opt/mysql
4:编辑配置文件/etc/my.cnf
########################################################################## [client] port = 3306 socket = /usr/local/mysql/mysql.sock default-character-set = utf8mb4 ########################################################################## [mysql] default-character-set=utf8mb4 socket=/usr/local/mysql/mysql.sock ########################################################################## [mysqld] port = 3306 skip_name_resolve = 1 socket = /usr/local/mysql/mysql.sock basedir = /usr/local/mysql/ datadir = /opt/mysql lower_case_table_names = 1 character-set-server = utf8mb4 init_connect = ‘SET NAMES utf8mb4‘ collation-server = utf8mb4_general_ci max_connections = 400 max_connect_errors = 1000 default-storage-engine = INNODB #事务隔离级别 transaction_isolation = READ-COMMITTED innodb_flush_log_at_trx_commit = 2 sync_binlog = 1 #TIMESTAMP如果没有显示声明NOT NULL,允许NULL值 explicit_defaults_for_timestamp = true ###查询缓存关闭 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 4M thread_stack = 512K sort_buffer_size = 2097152 binlog_cache_size = 16M join_buffer_size = 16M #一般设置物理存储的60% ~ 70% max_allowed_packet = 128M innodb_log_buffer_size = 16M innodb_buffer_pool_size = 256M #MySQL连接闲置超过一定时间后(单位:秒)将会被强行关闭 interactive_timeout = 1800 wait_timeout = 1800 sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" ######################################################################### #慢查询日志 slow_query_log = ON slow_query_log_file = /usr/local/mysql/slow.log long_query_time = 3 log_queries_not_using_indexes = ON log_slow_admin_statements = ON [mysqld_safe] #增加每个进程的可打开文件数量. open-files-limit = 28192 ########################################################################## #主从复制配置-半同步基于GTID复制 gtid_mode = ON server-id = 175 log_bin=master-binlog enforce-gtid-consistency = ON rpl_semi_sync_master_enabled = 1 rpl_semi_sync_master_timeout = 3000 # 1 second plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 5:初始化数据目录(初始化过程中会产生一个随机密码,记得记录一下,等下登录要用) /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mysql 6:启动mysq服务 拷贝启动脚本到init中 cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/ 修改启动脚本中的mysql安装路径和数据路径 启动服务 /etc/init.d/mysql.server start 停止服务 /etc/init.d/mysql.server stop 重启 /etc/init.d/mysql.server restart 7:登录后修改临时密码set
password
for
root@localhost=password(
‘123456‘
);
MySQL5.7 二进制安装
标签:gtid_mode text using gtid resolve ast bst null center