mysql主从安装配置

1、上传RPM安装压缩包mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar到/iflytek/software目录下

2、查看是否已经安装mariadb或mysql,已安则卸载:yum remove mariadb*

rpm -qa|grep mariadb

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

此处如果不卸载mariadb,第5步安装mysql-community-common-5.7.24-1.el7.x86_64.rpm报错冲突:

file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.28-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
	file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.28-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
	file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.28-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
	file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.28-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64

3.安装mysql5.7所需要的依赖:

yum install perl

离线安装perl:perl

tar -zxvf perl-5.26.1.tar.gz -C /opt

cd /opt/perl-5.26.1/

./Configure -des -Dprefix=/opt/perl

编译并安装:

make && make install

验证:perl -v

yum install net-tools

离线安装net-tools:

rpm -ivh net-tools-2.0-0.25.20131004git.el7.x86_64.rpm

4、解压tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

5、安装:

rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm --force --nodeps

安装client报错,缺失libncurses.so.5()(64bit)、 libtinfo.so.5()(64bit),

解决:yum install ncurses-compat-libs

直接安装server报错,提示缺失libsasl2.so.2()(64bit) ,然而不要此依赖也可以安装mysql

6、在/etc/my.cnf中修改数据存放目录:新建mysql-data数据存放目录并修改数据指向

mysql主从安装配置_第1张图片

7、启动MySQL服务

SElinux,暂时关闭:

setenforce 0 

getenforce(此处重启会失效)

vim /etc/selinux/config

SELINUX=enforcing改为permissive永久生效

service mysqld start

查看初始密码:

grep password /var/log/mysqld.log

如果没有密码,需要关闭mysql,清除data、log、/var/lib/mysql三个目录下的内容,然后再启动mysql,即出现了密码;

  1. 用初始密码登录:

Mysql -uroot -p初始密码;

  1. 降低密码安全策略,修改密码,开启远程连接,刷新:

set global validate_password_policy=0; 修改降低密码安全策略

ALTER USER 'root'@'localhost' IDENTIFIED BY 'bdl123456';

GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'bdl123456' WITH GRANT OPTION;

flush privileges; 

  1. 退出mysql登录,设置开机启动:

systemctl enable mysqld

systemctl daemon-reload

  1. 配置

[client]

default-character-set=utf8

[mysqld]

server-id=1

character-set-server=utf8

collation-server=utf8_general_ci

一下的配置需要在[mysqld]之下

mysql主从安装配置_第2张图片

详细配置项说明:linux mysql5.7.9 my.cnf详细配置参数详解 - Nice_keep-going - 博客园

  1. 配置基本配置,默认字符集utf8,设置事物隔离级别为reda_commited,导入表数据后需要给book_info创建全文索引(检查是否创建),具体/etc/my.cnf配置如下:

#log-bin=mysql-bin

##binlog记录内容的方式,记录被操作的每一行

#binlog_format = ROW

##对于binlog_format = ROW模式时,减少记录日志的内容,只记录受影响的列

#binlog_row_image = minimal

#O_DIRECT减少操作系统级别VFS的缓存和Innodb本身的buffer缓存之间的冲突

innodb_flush_method = O_DIRECT

#强所有发生的死锁错误信息记录到error.log中,之前通过命令行只能查看最近一次死锁信息

innodb_print_all_deadlocks = 1

#增加每个进程的可打开文件数量.

#open-files-limit = 28192

#

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

#datadir=/var/lib/mysql

datadir=/opt/doudoushu/mysql/data

#socket=/var/lib/mysql/mysql.sock

socket=/opt/doudoushu/mysql/data/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

  1. 保存配置,重启mysql服务:service mysqld restart
  1. 优化

参考:MySQL 5.6&5.7 性能优化 TOP10_nloneday-CSDN博客

注:查看mysql配置参数命令:连接mysql后,show variables和show status

1)修改最大连接数(默认151)。

先查看每个连接消耗的内存,命令如下:

SELECT CONCAT(ROUND(SUM(VARIABLE_VALUE)/(1024*1024)),'M') AS 'per_connection'

       FROM performance_schema.global_variables

       WHERE VARIABLE_NAME IN ('read_buffer_size', 'read_rnd_buffer_size', 'sort_buffer_size',

       'join_buffer_size', 'thread_stack', 'max_allowed_packet', 'net_buffer_length');

mysql主从安装配置_第3张图片

修改/etc/my.cnf,将max_connections值改为151

2)开启binlog(数据恢复用)

编辑/etc/my.cnf,设置server_id,开启log_bin、binlog_format和binlog_row_image,如下:

mysql主从安装配置_第4张图片

然后重启mysql:service mysqld restart

注:因为本地环境开启了SELinux,所以log_bin的目录采用默认的/var/log/mysql存放,生产上重新指定了,本地如要指定需要配置SELinux权限,暂不配置

3)innodb_flush_log_at_trx_commit(事务日志刷盘时机,当前默认1)和sync_binlog(二进制事务日志刷盘时机,当前默认1)看性能影响,后面考虑优化,目前暂不设置,采用默认值1

  1. 访问,无法连接防火墙

firewall-cmd --list-ports

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --reload

停电导致Mysql挂了

一般是由于服务器强制关机导致pid文件丢失。

解决办法
在/etc/my.cnf 中查看pid-file的位置

pid-file=/var/run/mysql/mysqld.pid
创建对应的目录并修改权限

mkdir -p /var/run/mysqld
chown mysql.mysql /var/run/mysqld

mysql添加用户和权限分配

配置用户本地 IP 访问 localhost, 127.0.0.1

create user 'tag'@'localhost' identified by 'tag123';

配置用户外网 IP 访问

create user 'tag'@'%' identified by 'tag123';

刷新权限

flush privileges;

create database tagDB;

授权

grant all privileges on tagDB.* to 'tag'@'%' identified by 'tag123';

mysql> grant 权限列表 on 库名 to 用户名@"客户端地址"

             identified by "密码"     //授权用户密码

             with grant option;       //有授权权限,可选项

权限列表

—— all             //所有权限  

—— usage       //无权限

—— select,update,insert        //个别权限

—— select,update (字段1, ... ,字段N)        //指定字段

库名

—— *.*             //所有库所有表

—— 库名.*        //一个库

—— 库名.表名   //一张表

用户名

—— 授权时自定义要有标识性

—— 存储在mysql库的user表里

客户端地址

—— %                          //所有主机

—— 192.168.233.%      //网段内的所有主机   

—— 192.168.233.1       //1台主机

—— localhost               //数据库服务器本机

你可能感兴趣的:(mysql,mysql,perl,数据库)