mysql 5.7.25 安装简介
1 卸载linux系统上自带的mysql插件(old版本)
rpm -qa|grep -i mysql
rpm –ev {包名} --nodeps
2 删除老版本mysql相关的安装目录命令
find / -name mysql
rm –rf {目录名}
3 安装包下载
官网下载 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz 编译过的安装包
tar -xzvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
4 主目录权限处理
查看组和用户情况
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
删除原mysql用户:userdel -r mysql,会删除其对应的组和用户
创建mysql组和mysql用户
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql (同理对应/var/lib/mysql)
5 修改配置文件:/etc/my.cnf
主库
[client]
#client character set
default_character_set = utf8
[mysqld]
#########general config##########
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#user who own mysql server
user = mysql
#base directory
basedir=/usr/local/mysql
#data directory
datadir=/var/lib/mysql/data
#default server character set
character_set_server = utf8
#default engines
default_storage_engine = innodb
#server id
server_id = 1
#server port
port = 3306
#max connections
max_connections = 4000
#skip name resolve
skip_name_resolve = on
#pid file
pid-file = /var/lib/mysql/log/mysql.pid
#connect timeout ,second
connect_timeout = 10
#close inactive connections ,second
wait_timeout = 300
#close interactive timeout ,second
interactive_timeout = 300
lower_case_table_names = 1
log_bin_trust_function_creators=1
######log configure####
#swith on general log
general_log = on
#location of general log
general_log_file = /var/lib/mysql/log/master_general.log
#swith on bin log
log_bin = /var/lib/mysql/log/mysql-bin
#bin log index file
log_bin_index = /var/lib/mysql/log/mysql-bin.index
#swith on slow log
slow_query_log = on
#location of slow qurey log
slow_query_log_file = /var/lib/mysql/log/mysql_slow.log
#time of slow qurey ,second
long_query_time=3
#swith on error log
log_error = /var/lib/mysql/log/mysql.err
#auto clean bin log ,day
expire_logs_days = 14
#binlog format set
binlog_format=row
innodb_buffer_pool_size = 32G # 50%-70% of total RAM
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
从库
[client]
#client character set
default_character_set = utf8
[mysqld]
#########general config##########
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#user who own mysql server
user = mysql
#base directory
basedir=/usr/local/mysql
#data directory
datadir=/var/lib/mysql/data
#default server character set
character_set_server = utf8
#default engines
default_storage_engine = innodb
#server id
server_id = 2
#server port
port = 3306
#max connections
max_connections = 4000
#skip name resolve
skip_name_resolve = on
#pid file
pid_file = /var/lib/mysql/log/mysql.pid
#connect timeout ,second
connect_timeout = 10
#close inactive connections ,second
wait_timeout = 300
#close interactive timeout ,second
interactive_timeout = 300
lower_case_table_names = 1
log_bin_trust_function_creators=1
slave-skip-errors=1032,1060,1062
######log configure####
#swith on general log
general_log = on
#location of general log
general_log_file = /var/lib/mysql/log/mysql_general.log
#swith on bin log
log_bin = /var/lib/mysql/log/mysql-bin
#bin log index file
log_bin_index = /var/lib/mysql/log/mysql-bin.index
#swith on slow log
slow_query_log = on
#location of slow qurey log
slow_query_log_file = /var/lib/mysql/log/mysql_slow.log
#time of slow qurey ,second
long_query_time=3
#swith on error log
log_error = /var/lib/mysql/log/mysql.err
#auto clean bin log ,day
expire_logs_days = 14
relay-log-index=/var/lib/mysql/log/relay-slave.index
relay-log=/var/lib/mysql/log/relay-slave
slave_net_timeout = 60
innodb_buffer_pool_size = 32G
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
6 创建文件/tmp/mysql.sock:设置用户组及用户,授权
touch /tmp/mysql.sock
chown mysql:mysql /tmp/mysql.sock
chmod 755 /tmp/mysql.sock
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql--datadir=/var/lib/mysql/data
8 安全启动mysql: ps -ef | grep mysql
./mysqld_safe --user=mysql &
9 查询默认密码在log_error日志里, 找到后保存到安全的地方
/var/lib/mysql/log/mysql.err
10 登陆设置新密码
cd /usr/local/mysql/bin/
./mysql -u root -p (log_error记录)
set password=password("123456");
grant all privileges on *.* to 'root'@'%' identified by '123456';
flush privileges; 到此安装流程完毕
11 开机服务启动设置:
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql (service mysql start stop启动)
chkconfig --add mysql
chkconfig --level 345 mysql on
chkconfig --list mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin (软连接 快捷方式)
12 配置主从同步
主库
添加同步专用账号 GRANT REPLICATION SLAVE,RELOAD,SUPER ON *.* TO 'slave'@'192.168.1.%' IDENTIFIED BY 'Attack@123';
flush privileges;
show master status;
从库
stop slave;
change master to master_host='192.168.1.60',master_user='slave',master_password='Attack@123',
master_log_file='mysql-bin.000001',master_log_pos=154;
start slave;
show slave status \G;
来源:oschina
链接:https://my.oschina.net/u/4315697/blog/4108911