MySql教程

CentOS 7二进制包部署MySQL 8.0

本文主要是介绍CentOS 7二进制包部署MySQL 8.0,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

CentOS 7二进制包部署MySQL 8.0
一、关闭防火墙
[root@node01 ~]# systemctl disable firewalld && systemctl stop firewalld
[root@node01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

二、关闭SElinux
[root@node01 ~]# sed -i "s#SELINUX=disabled#SELINUX=enforcing#g" /etc/selinux/config
[root@node01 ~]# getenforce
Disabled

临时关闭SElinux
[root@node01 ~]# setenforce 0
setenforce: SELinux is disabled

三、卸载centos自带数据库
[root@node01 ~]# rpm -qa | grep mariadb | xargs -i yum -y remove {}
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-6.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved
=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Removing:
mariadb-libs x86_64 1:5.5.56-2.el7 @anaconda 4.4 M
Removing for dependencies:
postfix x86_64 2:2.10.1-6.el7 @anaconda 12 M

Transaction Summary
=======================================================================================
Remove 1 Package (+1 Dependent package)

Installed size: 17 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : 2:postfix-2.10.1-6.el7.x86_64 1/2
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 2/2
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 1/2
Verifying : 2:postfix-2.10.1-6.el7.x86_64 2/2

Removed:
mariadb-libs.x86_64 1:5.5.56-2.el7

Dependency Removed:
postfix.x86_64 2:2.10.1-6.el7
Complete!
[root@node01 ~]# rpm -qa | grep mariadb

四、添加用户组及用户
[root@node01 ~]# groupadd mysql && useradd -g -s nologin mysql mysql
[root@node01 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@node01 ~]# echo mysql | --stdin passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

五、创建MySQL相关目录
[root@node01 ~]# mkdir -p /data/mysql/{data,logs}
[root@node01 ~]# chown -R mysql.mysql /data

六、下载MySQL 8.0安装包,上传并解压
[mysql@node01 ~]#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.18-linux-glibc2.12-x86_64.tar

解压MySQL安装包:
[mysql@node01 ~]$ tar -zxvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz /usr/local

七、创建mysql安装包软连接
[root@node01 data]# ln -s /data/mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql
[root@node01 data]# chown -R mysql.mysql /usr/local/mysql*

八、创建my.cnf参数文件
[root@node01 data]# vim /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql/data
log_error=/data/mysql/data/mysqld.err
server_id=1
log_bin=/data/mysql/logs/mysql-bin
log_bin_index=/data/mysql/logs/mysql-bin.index
binlog_format=row

九、配置用户环境变量
[mysql@node01 ~]$ vim .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

export PATH=$PATH:$HOME/.local/bin:$HOME/bin
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

[root@node02 ~]# cat >> /etc/profile <<EOF
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
EOF
source /etc/profile

十、初始化MySQL数据库
[mysql@node01 ~]$ mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data

十一、添加MySQL服务
[root@node01 data]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

十二、启动MySQL数据库、登录数据库
[mysql@node01 ~]$ /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[mysql@node01 ~]$ mysql -h127.0.0.1 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

十三、配置mysql数据库自动启动
[root@node01 data]# chkconfig --add mysqld
[root@node01 data]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off

这篇关于CentOS 7二进制包部署MySQL 8.0的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!