CentOS7.4下Mysql8.0.12安装与主从配置

首先下载安装包:mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz,并上传到Linux服务器的/home/software目录下。

1、解压缩安装包

cd /home/software

xz -d mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz

tar -xvf mysql-8.0.12-linux-glibc2.12-x86_64.tar -C /home/local/

mv /home/local/mysql-8.0.12-linux-glibc2.12-x86_64 /home/local/mysql

2、创建mysql用户组和用户

groupadd mysql

useradd -g mysql mysql

3、创建mysql数据目录

cd /home/local/mysql

mkdir data

4、更改mysql目录权限

chown -R mysql:mysql /home/local/mysql

chmod -R 775 /home/local/mysql/data

5、更改mysql配置文件

vi /etc/my.cnf

[mysqld]

server-id                      = 1

port                           = 3306

mysqlx_port                    = 33060

basedir                         =/home/local/mysql

datadir                        = /home/local/mysql/data

socket                         = /tmp/mysql.sock

mysqlx_socket                  =/tmp/mysqlx.sock

pid-file                       = /tmp/mysqld.pid

log-error                      = error.log

slow-query-log                 = 1

slow-query-log-file            = slow.log

long_query_time                = 0.2

log-bin                        = bin.log

relay-log                      = relay.log

binlog_format                 =ROW

relay_log_recovery            = 1

character-set-client-handshake = FALSE

character-set-server           = utf8mb4

collation-server               = utf8mb4_unicode_ci

init_connect                   ='SET NAMES utf8mb4'

innodb_buffer_pool_size        = 1G

join_buffer_size               = 128M

sort_buffer_size               = 2M

read_rnd_buffer_size           = 2M

log_timestamps                 = SYSTEM

lower_case_table_names         = 1

default_authentication_plugin  =mysql_native_password

6、设置mysql服务为系统服务

cp -a /home/local/mysql/support-files/mysql.server /etc/init.d/mysql

chmod +x /etc/rc.d/init.d/mysql

chkconfig --add mysql

7、配置全局环境变量

vi /etc/profile

在 profile 文件底部添加如下两行配置,保存后退出

export PATH=/home/local/mysql/bin:/home/local/mysql/lib:$PATH

设置环境变量立即生效

 source /etc/profile

8、初始化数据库

mysqld --initialize --user=mysql --basedir=/home/local/mysql --datadir=/home/local/mysql/data

9、启动mysql服务

service mysql start

10、查看root用户对应的初始密码

cat /home/local/mysql/data/error.log | grep -i password

生成的初始密码要记录下来例如:SMpiLN8hu(A2

11、登陆mysql数据库

mysql -uroot –p

然后输入密码

修改临时密码:mysql> alter user 'root'@'localhost' identified by 'root123!';

12、以root用户重新登录数据库

mysql -uroot -proot123!

接下来就可以创建自己需要的数据库实例了,并用navicat等客户端测试连接。

13、Mysql主从配置

①主节点:

1、临时关闭SELinux

setenforce 0

2、更改mysql配置文件

vi /etc/my.cnf添加如下内容:

server_id = 1

log-bin=mysql-bin

3、创建数据复制用户

mysql -uroot -proot123!

mysql>create user repadmin@'%' identified with mysql_native_password by 'RepAdmin123!';(此处有坑,可以先执行alter user repadmin@'%' identified with mysql_native_password by 'RepAdmin123!';再执行这句话)

mysql>grant all privileges on *.* to repadmin@'%' with grant option;

mysql>flush privileges;

mysql>quit;

4、重启mysql服务

service mysql restart

5、登陆mysql,获取主节点当前binary log文件名和位置(position)

mysql -uroot -proot123!

mysql>show master status;

CentOS7.4下Mysql8.0.12安装与主从配置_第1张图片

②从节点:

1、临时关闭SELinux

setenforce 0

2、更改mysql配置文件

vi /etc/my.cnf添加如下内容:

server_id = 2

3、重启mysql服务

service mysql restart

4、登陆mysql,设置主节点参数

mysql -uroot -proot123!

mysql>change master to

master_host='172.168.90.24',

master_user='repadmin',

master_password='RepAdmin123!',

master_log_file='mysql-bin.000006',

master_log_pos=155;

5、查看主从同步状态

mysql> show slave status\G;

6、开启主从同步

mysql> start slave;

7、查看主从同步状态,出现如下截图表示主从已经同步成功

mysql> show slave status\G;

CentOS7.4下Mysql8.0.12安装与主从配置_第2张图片

你可能感兴趣的:(CentOS7.4,Mysql8.0,安装配置)