当前位置:Gxlcms > 数据库问题 > Centos7 安装 MySQL5.7

Centos7 安装 MySQL5.7

时间:2021-07-01 10:21:17 帮助过:16人阅读

国外源:

# wget -P /opt/  https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

3.创建用户

# useradd  -s /sbin/nologin  -M mysql

4.解压软连接MySQL二进制包

# mkdir /opt/mysql/
# tar zxf /opt/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /opt/mysql/
# cd /usr/local/
# ln -s /opt/mysql/mysql-5.7.18-linux-glibc2.5-x86_64 mysql

5.创建数据库相关目录

# mkdir -pv /data/mysql/mysql3306/{data,logs,tmp} 

6.修改相关目录权限

# chown -R mysql.mysql /usr/local/mysql
# chown -R mysql.mysql /data

7.创建配置文件

我们使用的配置文件为:/etc/my.cnf

# cat > /etc/my.cnf << EOF
###### base ######
#my.cnf
[client]
port = 3306
socket = /tmp/mysql3306.sock

[mysql]
prompt="\u@\h [\d]>" 
no-auto-rehash

[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
tmpdir = /data/mysql/mysql3306/tmp
port = 3306
socket = /tmp/mysql3306.sock
event_scheduler = 0

#timeout
interactive_timeout = 300
wait_timeout = 300

#character set
character-set-server = utf8

open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
lower_case_table_names =1

###### GTID ######
gtid-mode = on
enforce-gtid-consistency=1

###### symi replication ######
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000 # 1 second
#rpl_semi_sync_slave_enabled=1

####### slow log ######
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1

####### binlog ######
binlog_format = row
server-id = 1003306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
max_binlog_size = 256M
sync_binlog = 0
expire_logs_days = 10
#procedure 
log_bin_trust_function_creators=1

####### relay log ######
skip_slave_start = 1
max_relay_log_size = 128M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=relay-bin
relay-log-index = relay-bin.index
log_slave_updates = ON
#slave-skip-errors=1032,1053,1062
#skip-grant-tables

####### buffers & cache ######
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 200
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M

#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 100M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
EOF

8.初始化数据库

# cd /usr/local/mysql
# ./bin/mysqld --defaults-file=/etc/my.cnf   --initialize

9.创建MySQL启动脚本

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
# /etc/init.d/mysqld start 

10.创建环境变量

# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile

11.修改初始密码

查看初始密码:

# grep "password" /data/mysql/mysql3306/data/error.log    
2017-05-08T07:49:40.620503Z 1 [Note] A temporary password is generated for root@localhost: q=8jh*JpNar)

初始密码为: q=8jh*JpNar) 每次初始化密码都不会相同;
登录数据库修改密码为:unixfbi.com

# mysql -uroot -p初始密码
mysql> alter user user() identified by ‘unixfbi.com‘;
或者:
mysql> SET PASSWORD=PASSWORD(‘unixfbi.com‘);
mysql> flush privileges;

或者:

# PASSWD=$(grep ‘password is‘ /data/mysql/mysql3306/data/error.log  | awk ‘{print $NF}‘)

# mysql -uroot -p"$PASSWD" --connect-expired-password -e "alter user user() identified by ‘unixfbi.com‘;"

参考文档

https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
http://database.51cto.com/art/201108/285365.htm

本文出自 “运维特工” 博客,转载请务必保留原文链接 和 http://www.unixfbi.com

Centos7 安装 MySQL5.7

标签:head   format   ror   eric   sql   serve   binlog   method   client   

人气教程排行