赞
踩
[root@mysql ~]# sed -i '$aexport PATH=/usr/local/mysql/bin/:$PATH' /etc/profile //加到环境变量
[root@mysql ~]# source /etc/profile //使配置环境生效配置开机自启
[root@mysql ~]# chkconfig --list //列举
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@mysql ~]# chkconfig --add mysql8
[root@mysql ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
mysql8 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
//启动2345
[root@mysql ~]# chkconfig mysql8 on
[root@mysql ~]# vim /usr/local/mysql/my.cnf //配置文件
[mysqld]
basedir=/usr/local/mysql // 这是 MySQL 安装目录的路径。所有与 MySQL 相关的基础文件(例如二进制文件和库文件)都位于此目录下。
datadir=/usr/local/mysql/data // 这是 MySQL 数据目录的路径。所有数据库文件(包括数据、索引等)都存储在这个目录中。
socket=/tmp/mysql.sock //指定用于 MySQL 进程间通信的 UNIX 套接字文件的位置。这个文件允许客户端和服务器之间通过 UNIX socket 进行连接。
activate_all_roles_on_login=on //这项配置表示在用户登录 MySQL 时,系统会自动激活与该用户关联的所有角色。如果设定为 off,则只有用户明确请求的角色(s)会被激活。
[root@mysql ~]# service mysql8 restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@mysql ~]# ll /tmp //查看套字节文件
总用量 8
srwxrwxrwx. 1 mysql mysql 0 8月 6 10:10 mysql.sock
-rw-------. 1 mysql mysql 5 8月 6 10:10 mysql.sock.lock
srwxrwxrwx. 1 mysql mysql 0 8月 6 10:10 mysqlx.sock
-rw-------. 1 mysql mysql 5 8月 6 10:10 mysqlx.sock.lock
主从mysql
两台mysql服务器
- 主(192.168.1.129) 从(192.168.1.130)有yum本地源,阿里云镜像
- 主从:
- [root@zmysql ~]# systemctl stop firewalld
- [root@zmysql ~]# systemctl disable firewalld
- [root@zmysql ~]# vim /etc/selinux/config
- SELINUX=disabled
- 配置时间同步
- [root@zmysql ~]# yum -y install ntpdate.x86_64
- [root@zmysql ~]# ntpdate cn.ntp.org.cn
- [root@zmysql ~]# yum -y install rsync
主:
- [root@localhost ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar
- [root@localhost ~]# vim mysql.sh //编写安装脚本
- #!/bin/bash
- yum list installed |grep libaio
- if [ $? ne 0 ]; then
- yum -y install libaio
- fi
- echo libaio yes
- rm -rf /etc/my.cnf
- echo remo my.cnf yes
- tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
- echo tar zx yes
- cp -r ~/mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
- echo copy file to /usr/local/mysql yes
- mkdir /usr/local/mysql/mysql-files
- echo mysql-files yes
- grep mysql /etc/passwd
- useradd -r -s /sbin/nologin mysql
- chown mysql:mysql /usr/local/mysql/mysql-files
- chmod 750 /usr/local/mysql/mysql-files
- /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
- /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
- cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
- sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile
- source /etc/profile
- [root@localhost ~]# source mysql.sh //运行脚本
- [root@zmysql ~]# vim /usr/local/mysql/my.cnf //编写配置文件
- [mysqld]
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- socket=/tmp/mysql.sock
- port=3306
- log-error=/usr/local/mysql/data/db01-master.err
- log-bin=/usr/local/mysql/data/binlog
- server-id=10
- character_set_server=utf8mb4
- [root@zmysql ~]# service mysql8 restart //重启服务
- Shutting down MySQL. SUCCESS!
- Starting MySQL. SUCCESS!
从:
- [root@localhost ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar
- [root@localhost ~]# vim mysql.sh //编写脚本,注释掉其中两行
- #!/bin/bash
- yum list installed |grep libaio
- if [ $? ne 0 ]; then
- yum -y install libaio
- fi
- echo libaio yes
- rm -rf /etc/my.cnf
- echo remo my.cnf yes
- tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
- echo tar zx yes
- cp -r ~/mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
- echo copy file to /usr/local/mysql yes
- mkdir /usr/local/mysql/mysql-files
- echo mysql-files yes
- grep mysql /etc/passwd
- useradd -r -s /sbin/nologin mysql
- chown mysql:mysql /usr/local/mysql/mysql-files
- chmod 750 /usr/local/mysql/mysql-files
- #/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
- #/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
- cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
- sed -i '$aexport PATH=/usr/local/mysql/bin:$PATH' /etc/profile
- source /etc/profile
- [root@localhost ~]# vim /usr/local/mysql/my.cnf
- [mysqld]
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
- socket=/tmp/mysql.soc
- port=3310
- log-error=/usr/local/mysql/data/db01-slave.err
- relay-log=/usr/local/mysql/data/relaylog
- server-id=11
- character_set_server=utf8mb4
回到主服务器
- [root@zmysql ~]# service mysql8 stop //停止服务
- [root@zmysql ~]# rm -rf /usr/local/mysql/data/auto.cnf //这个操作保证两个mysql服务是一起的,因为这个文件存放的是mysql服务器的uuid,uuid保证了mysql服务器的唯一性,所以删除以后,两个服务器就可以做主从
- [root@zmysql ~]# rsync -av /usr/local/mysql/data root@192.168.1.20:/usr/local/mysql/
- [root@zmysql ~]# service mysql8 start
回到从服务器
- [root@localhost ~]# service mysql8 start
- [root@localhost ~]# mysql -P3310 -p1812354953Gf. //使用主服务器账号密码可以登陆,默认就是用root登陆
- mysql> exit
- Bye
主服务器
- [root@zmysql ~]# mysql -p1812354953Gf.
- mysql> create user 'gao'@'%' identified by 'abc_123';
- Query OK, 0 rows affected (0.00 sec)
- mysql> grant replication slave on *.* to 'gao'@'%';
- Query OK, 0 rows affected (0.00 sec)
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- mysql> show variables like 'server_id';
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | server_id | 10 |
- +---------------+-------+
- 1 row in set (0.00 sec)
- mysql> flush tables with read lock; //锁定表
- Query OK, 0 rows affected (0.00 sec)
- mysql> show master status; //查看二进制文件
- +---------------+----------+--------------+------------------+-------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
- +---------------+----------+--------------+------------------+-------------------+
- | binlog.000008 | 846 | | | |
- +---------------+----------+--------------+------------------+-------------------+
- 1 row in set (0.00 sec)
去从服务器;
- mysql> change master to master_host='192.168.1.129', master_user='gao', master_password='abc_123', master_port=3306, master_log_file='binlog.000008',
- master_log_pos=846;
- Query OK, 0 rows affected, 9 warnings (0.00 sec)
- mysql> start slave;
- mysql> show slave status \G;
- [root@localhost ~]# mysql -ugao -pabc_123 -h 192.168.1.129 -P3306 --get-server-public-key
- mysql> exit
- Bye
- [root@localhost ~]# mysql -P3310 -p1812354953Gf.
- mysql> stop slave;
- Query OK, 0 rows affected, 1 warning (0.01 sec)
- mysql> reset slave;
- Query OK, 0 rows affected, 1 warning (0.02 sec)
- mysql> change master to master_host='192.168.1.129', master_user='gao', master_password='abc_123', master_port=3306, master_log_file='binlog.000008', master_log_pos=846;
- Query OK, 0 rows affected, 9 warnings (0.01 sec)
- mysql> start slave;
- Query OK, 0 rows affected, 1 warning (0.02 sec)
- mysql> show slave status\G
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。