同步时间
yum -y install ntpdate.x86_64
ntpdate ntp.ntsc.ac.cn
两台主机都要安装 libaio 和rsync
yum -y install rsync
rpm -qa |grep libaio查看是否安装 没有就安装
然后安装mysql8.0的安装包解压
[root@msater ~]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar
[root@msater ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
[root@msater ~]# cp -r mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
[root@msater mysql]# rm -rf /etc/my.cnf (不删除后面不能初始化出现data)
[root@msater ~]# cd /usr/local/mysql/
[root@msater mysql]# ls (下面就是成功)
bin docs include lib LICENSE man README share support-files
[root@msater mysql]# mkdir mysql-files
[root@msater mysql]# useradd -r -s /sbin/nologin mysql
[root@msater mysql]# id mysql (如果有这个账户就不用创建)
uid=997(mysql) gid=995(mysql) 组=995(mysql)
[root@msater mysql]# chown mysql:mysql ./mysql-files/
[root@msater mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql (初始化)
[root@msater mysql]# ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
[root@msater mysql]# cp support-files/mysql.server /etc/init.d/mysql8
[root@msater mysql]# vim my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
[root@msater mysql]# service mysql8 start
[root@msater mysql]# ./bin/mysql -P3306 -pIirM?=bbd9n+ (进入mysql -p后面是前面生成的密码)
mysql> alter user 'root'@'localhost' identified by '123';(修改密码)
[root@msater mysql]# ./bin/mysql -P3306 -p123 (重新登陆)
[root@msater mysql]# vim my.cnf
[root@msater mysql]# service mysql8 start (重启服务)
[root@msater mysql]# ll /usr/local/mysql/data/ (查看里面写的配置文件是否成功)
[root@msater mysql]# ll /tmp
从服务器:
下载mysql8的包并解压
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar
tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz
cp -r mysql-8.0.33-linux-glibc2.12-x86_64 /usr/local/mysql
useradd -r -s /sbin/nologin mysql
mkdir /usr/local/mysql/mysql-files
chown mysql:mysql /usr/local/mysql/mysql-files/
ll /usr/local/mysql/
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
主服务器:
[root@msater mysql]# rm -rf /usr/local/mysql/data/auto.cnf
[root@msater mysql]# ls /usr/local/mysql/data/
[root@msater mysql]# rsync -av /usr/local/mysql/data root@192.168.1.32:/usr/local/mysql/
从服务器:
[root@slave ~]# vim /usr/local/mysql/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3310
log-error=/usr/local/mysql/data/err.log
relay-log=/usr/local/mysql/data/relaylog
server-id=12
character_set_server=utf8mb4
[root@slave ~]# service mysql8 start(后面照下面的做 ---主从特权 实现)
mysql的增删改查: