前言:
今天你们对“centos7的mysql配置文件”大致比较注重,兄弟们都想要知道一些“centos7的mysql配置文件”的相关知识。那么小编也在网摘上搜集了一些关于“centos7的mysql配置文件””的相关资讯,希望各位老铁们能喜欢,大家快快来了解一下吧!环境:centos7.6,mysql5.7.29
系统
IP
备注
centos7.6
192.168.9.90
主库
centos7.6
192.168.9.91
从库
下载mysql mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz,并 解压(root用户操作):
tar -xvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gzmv mysql-5.7.29-linux-glibc2.12-x86_64 /usr/local/mysql
2.配置环境变量,(root用户操作)
echo "MYSQL_HOME=/usr/local/mysql" >> /etc/profileecho "PATH=$MYSQL_HOME/bin:$PATH" >> /etc/profileecho "export PATH" >> /etc/profilesource /etc/profile
3.创建用户mysql,数据目录,以及日志等(root用户操作)
useradd mysqlmkdir -p /data/mysql /data/mysql-bin /data/tmp mkdir -p /usr/local/mysql/logschown -R mysql:mysql /datachown -R mysql:mysql /usr/local/mysql
4.mysql启动文件,并设置开机启动(root用户操作)
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqlchkconfig mysql on
5.编辑配置文件/etc/my.cnf,建议数据目录和binlog目录分开,不要在同一个目录。其他参数可以根据实际调整优化。这个配置文件是主库的配置文件my.cnf(root用户操作)
[client]port = 3306default-character-set=utf8[mysqld]basedir = /usr/local/mysqldatadir=/data/mysqlport = 3306character-set-server=utf8default_storage_engine = InnoDB socket=/tmp/mysql.socksymbolic-links=0ft_min_word_len=1skip-external-lockingskip-name-resolvemax_allowed_packet=256Mback_log = 500max_connections = 5000max_user_connections = 1000max_connect_errors = 10000000slow_query_loglong_query_time = 2lower_case_table_names=1sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLEStransaction_isolation=READ-COMMITTEDgroup_concat_max_len=102400innodb_buffer_pool_size=512M log_bin_trust_function_creators=1###join_buffer_size = 128Mtmp_table_size = 64Mtmpdir = /data/tmpread_buffer_size = 16M#MySQL的随机读缓冲区大小read_rnd_buffer_size = 8M#MySQL的顺序读缓冲区大小sort_buffer_size = 8M##########主从配置########### log-bin=/data/mysql-bin/mysql-binbinlog_format=mixed server-id=1 //主库为1 ,从库为2,这里不能一样binlog-do-db=db1 //需要复制的数据库名binlog-do-db=db2 //需要复制的数据库名binlog-do-db=db3 //需要复制的数据库名binlog-ignore-db=mysql binlog-ignore-db=information_schemabinlog-ignore-db=sys[mysqldump]quick#max_allowed_packet = 40M[mysql]no-auto-rehash[mysqld_safe]log-error=/usr/local/mysql/logs/error.logpid-file=/usr/local/mysql/logs/mysql.pid
6.数据库初始化
su - mysql cd /usr/local/mysql/bin./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
初始化成功会有初始root登陆密码:
7.登陆修改初始密码:
mysql -uroot -p -hlocalhostalter user user() identified by "passwd";
8.在主库上创建用于复制的账户:
grant replication slave on *.* to user123@'192.168.9.91' identified by 'passwd';flush privileges;
在从库上操作从步骤1-7,其中配置5配置文件,从库不一样server-id=2,从库的/etc/my.cnf配置文件:
[client]port = 3306default-character-set=utf8[mysqld]basedir = /usr/local/mysqldatadir=/data/mysqlport = 3306character-set-server=utf8default_storage_engine = InnoDB socket=/tmp/mysql.socksymbolic-links=0ft_min_word_len=1skip-external-lockingskip-name-resolvemax_allowed_packet=256Mback_log = 500max_connections = 5000max_user_connections = 1000max_connect_errors = 10000000slow_query_loglong_query_time = 2lower_case_table_names=1sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLEStransaction_isolation=READ-COMMITTEDgroup_concat_max_len=102400innodb_buffer_pool_size=512M log_bin_trust_function_creators=1###join_buffer_size = 128Mtmp_table_size = 64Mtmpdir = /data/tmpread_buffer_size = 16M#MySQL的随机读缓冲区大小read_rnd_buffer_size = 8M#MySQL的顺序读缓冲区大小sort_buffer_size = 8M##########主从配置########### log-bin=/data/mysql-bin/mysql-binbinlog_format=mixed server-id=2 //主库为1 ,从库为2,这里不能一样binlog-do-db=db1 //需要复制的数据库名binlog-do-db=db2 //需要复制的数据库名binlog-do-db=db3 //需要复制的数据库名binlog-ignore-db=mysql binlog-ignore-db=information_schemabinlog-ignore-db=sys[mysqldump]quick#max_allowed_packet = 40M[mysql]no-auto-rehash[mysqld_safe]log-error=/usr/local/mysql/logs/error.logpid-file=/usr/local/mysql/logs/mysql.pid
9.从库配置好了,之后,验证一下刚才步骤8创建的用户:
mysql -uuser123 -p -h192.168.9.90
10.在从库登陆root用户
在从库上指定主库的连接信息,并开启同步进程:
change master to master_host='192.168.9.90',master_user='user23',master_password='passwd';start slave;show slave status \G;
在主库查看
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。