企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 查看可用配置文件 ## 版本 系统:Red Hat Enterprise Linux Server release 7.3 (Maipo) mysql版本:5.6.39 ~~~ /usr/bin/mysql --verbose --help | grep -A 1 'Default options' ~~~ ## 1. 安装mysql(5.6.38) 1. 安装mysql 首先查看是否存在mysql ~~~ rpm -qa | grep -i mysql yum -y remove mysql-libs* ~~~ 依赖: ~~~ yum -y install net-tools autoconf rpm -e mariadb-libs-1:5.5.52-1.el7.x86_64 --nodeps ~~~ ### 1.1 创建用户 ~~~ groupadd mysql useradd -r -g mysql mysql ~~~ ### 1.2 解压 ~~~ tar -xvf MySQL-5.6.39-1.el7.x86_64.rpm-bundle.tar ~~~ ### 1.3 安装server ~~~ rpm -ivh MySQL-server-5.6.39-1.el7.x86_64.rpm ~~~ ### 1.4 安装client ~~~ rpm -ivh MySQL-devel-5.6.39-1.el7.x86_64.rpm rpm -ivh MySQL-client-5.6.39-1.el7.x86_64.rpm ~~~ ### 1.5 修改配置文件 ~~~ cp /usr/share/mysql/my-default.cnf /etc/my.cnf ~~~ ### 1.6 初始化数据库 直接将/var/lib/mysql/目录下的mysql数据复制过去即可,不用重新初始化数据到/data/mysqldata目录 ~~~ mkdir -p /data/mysqldata chown mysql.mysql /data/mysqldata service mysql start ~~~ ### 1.7 修改密码 ~~~ cat /root/.mysql_secret mysql -uroot -p'UA1zL8P9QzNJBcs1' SET PASSWORD = PASSWORD('4rfv$RFV'); ~~~ ## 2. 主从搭建 ~~~ cp -r /var/lib/mysql/* /data/mysqldata/ chown -R mysql.mysql /data/mysqldata mkdir /var/log/mysql chown mysql.mysql /var/log/mysql setenforce 0 vim /etc/sysconfig/selinux 把SELINUX=enforcing改为SELINUX=disabled ~~~ ### 2.1 修改主服务器配置 ~~~ vim /etc/my.cnf 在【mysqld】添加 [client] port = 3306 socket = /data/mysqldata/mysqld.sock default-character-set = utf8 [mysqld_safe] socket =/data/mysqldata/mysqld.sock nice = 0 [mysqld] user = mysql pid-file = /data/mysqldata/mysqld.pid socket = /data/mysqldata/mysqld.sock port = 3306 basedir = /usr datadir = /data/mysqldata tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP max_connections = 200 query_cache_limit = 1M query_cache_size = 16M log_error = /var/log/mysql/error.log expire_logs_days = 10 max_binlog_size = 100M character-set-server=utf8 server-id = 1 log_bin = /var/log/mysql/mysql-bin.log sync_binlog=1 binlog_format=mixed lower_case_table_names = 1 innodb_buffer_pool_size=1G [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] default-character-set=utf8 [isamchk] key_buffer = 16M ~~~ 重启mysql ### 2.2 修改从服务器配置 ~~~ vim /etc/my.cnf 在【mysqld】添加 [client] port = 3306 socket = /data/mysqldata/mysqld.sock default-character-set = utf8 [mysqld_safe] socket = /data/mysqldata/mysqld.sock nice = 0 [mysqld] user = mysql pid-file = /data/mysqldata/mysqld.pid socket = /data/mysqldata/mysqld.sock port = 3306 basedir = /usr datadir = /data/mysqldata tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP max_connections = 200 query_cache_limit = 1M query_cache_size = 16M log_error = /var/log/mysql/error.log expire_logs_days = 10 max_binlog_size = 100M character-set-server=utf8 lower_case_table_names = 1 server-id=2 log-bin=/var/log/mysql/mysql-bin.log innodb_buffer_pool_size=1G [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] default-character-set=utf8 [isamchk] key_buffer = 16M ~~~ ### 2.3 重启主、从服务器的mysql服务 ~~~ service mysql restart ~~~ 不行的话就(修改了pid位置) ~~~ ps -ef|grep mysql kill -9 进程号 ~~~ ### 2.4登录主服务器mysql ~~~ GRANT REPLICATION SLAVE ON *.* TO 'systop'@'192.168.%' IDENTIFIED BY 'systop'; FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; 记下: file = mysqlmaster-bin.000001和 position = 329 ~~~ ### 2.5 导出主mysql数据 ~~~ mysqldump -uroot -p -P3306 --all-databases --triggers --routines --events >mysqlall.sql ~~~ ### 2.6 解锁 ~~~ UNLOCK TABLES; ~~~ ### 2.7 将数据文件远程拷贝到从服务器 ~~~ scp mysqlall.sql 192.168.X.X:/tmp/ ~~~ ### 2.8 从服务器导入数据 ~~~ mysql -uroot -p -h127.0.0.1 -P3306 < /tmp/mysqlall.sql ~~~ ### 2.9 从服务器执行 ~~~ CHANGE MASTER TO MASTER_HOST='192.168.4.101', MASTER_USER='systop',MASTER_PASSWORD='systop',MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=120; ~~~ ### 2.10 从服务器执行 ~~~ start slave; show slave status \G; 查看: Slave_IO_Running: Yes Slave_SQL_Running: Yes 都显示yes表示启动正常 ~~~ **主意,如果Slave_IO_Running一直显示Connecting,则很有可能是防火墙的原因** ~~~ firewall-cmd --permanent --add-port=3306/tcp firewall-cmd --reload ~~~ ## 安装mysql(5.7.22) 1. 安装mysql 首先查看是否存在mysql ~~~ rpm -qa | grep -i mysql yum -y remove mysql-libs* ~~~ ~~~ rpm -qa|grep mariadb rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps ~~~ 依赖: ~~~ yum -y install net-tools autoconf ~~~ 1.1 创建用户 ~~~ groupadd mysql useradd -r -g mysql mysql ~~~ 1.2 解压 ~~~ tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar ~~~ 1.3 安装client ~~~ rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.22-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm ~~~ 1.4 安装server ~~~ rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm ~~~ 1.5 修改配置 修改MySQL服务器配置 ~~~ mkdir -p /var/log/mysql chown -R mysql.mysql /var/log/mysql mkdir -p /usr/share/mysql chown -R mysql.mysql /usr/share/mysql mkdir -p /var/log/mysql chown -R mysql.mysql /var/log/mysql ~~~ ~~~ vim /etc/my.cnf [client] default-character-set = utf8 [mysqld_safe] nice = 0 [mysqld] user = mysql port = 3306 tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 max_connections = 200 query_cache_limit = 1M query_cache_size = 16M log_error = /var/log/mysql/error.log expire_logs_days = 10 max_binlog_size = 100M character-set-server=utf8 server-id = 1 log_bin = /var/lib/mysql/mysql-bin.log sync_binlog=1 binlog_format=mixed lower_case_table_names = 1 innodb_buffer_pool_size=1G [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] default-character-set=utf8 ~~~ 重启mysql 1.6 初始化数据库 ~~~ mysqld --initialize service mysqld start ~~~ 1.7 修改密码 ~~~ grep 'temporary password' /var/log/mysqld.log mysql -uroot -p'UA1zL8P9QzNJBcs1' SET PASSWORD = PASSWORD('4rfv$RFV'); ~~~