【MySQL】之Centos7.4 二进制方式安装部署安装Mysql 5.7版本

it2024-04-10  55

【MySQL】之Centos7.4 二进制方式安装部署安装Mysql 5.7版本

 

目录

【MySQL】之Centos7.4 二进制方式安装部署安装Mysql 5.7版本

项目需求:

一、数据库软件的下载

1、安装系统环境准备

2、二进制安装包下载。

二、数据库软件安装部署

1、环境检查。安装服务器上是否存在Mariadb数据库环境,如果存在需要卸载并清除默认的数据库配置文件。

2、安装依赖包,并解压到指定目录下,添加环境变量。

3、创建数据目录,用户。

4、数据库初始化

5、mysql配置文件

6、复制拷贝启动脚本并启动数据库,查看数据进程和监听端口。

7、登陆数据库

三、数据库密码修改

1、因在数据库初始化完成后,登陆数据库时,由于数据库密码问题,需要跳过授权表并重新设置数据库登陆密码。

2、完成用户密码修改和授权后,重新关闭并启动数据库。


项目需求:

 Linux操作系统上安装部署Mysql数据库,深入学习或企业生成环境没有上网环境时,无法通过yum方式安装部署,可通过二进制安装部署所需要的数据库,选择对应的数据库版本并完成数据库的安装,开始学习或使用数据库。

(1)深入学习研究,渴望成为DBA。

(2)业务应用需求,能够在无上网环境下安装部署数据库。

(3)了解MySQL数据库的安装部署过程。


一、数据库软件的下载

1、安装系统环境准备

操作系统:centos7.4    

地址:172.21.209.125

关闭操作系统的防火墙并禁用Selinux。

2、二进制安装包下载。

2.1、mysql数据库官网地址

https://www.mysql.com/

2.2、数据库下载地址

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

3.3、版本选择下载步骤:

第一:选择下载产品

第二:选择社区版,可以选择下载最新版本和历史版本。

第三、选择历史版本并下载mysql5.7

第四、选择产品版本和操作系统类型,下载对应的数据库安装包。

第五、下载后,将压缩包上传到指定的目录下。如data目录下。

[root@mysql03 data]# pwd /data [root@mysql03 data]# ll mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -rw-r--r-- 1 root root 660017902 Mar 24 2020 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

二、数据库软件安装部署

1、环境检查。安装服务器上是否存在Mariadb数据库环境,如果存在需要卸载并清除默认的数据库配置文件。

检查mariadb数据库环境 [root@mysql03 ~]# rpm -qa|grep mariadb 卸载移除mariadb数据库 [root@mysql03 ~]# yum remove -y mariadb-* 删除数据库默认配置文件 [root@mysql03 ~]# rm -rf /etc/my.cnf

2、安装依赖包,并解压到指定目录下,添加环境变量。

安装环境依赖包 yum install -y libaio-devel 查看二进制安装包 [root@mysql03 data]# ll mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -rw-r--r-- 1 root root 660017902 Mar 24 2020 mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz 解压到指定指定目录下 [root@mysql03 data]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ 创建软连接 [root@mysql03 local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql [root@mysql03 local]# ll mysql lrwxrwxrwx 1 root root 36 Oct 21 15:17 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/ 添加环境变量 [root@mysql03 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile && source /etc/profile 在任意目录下输入mysql命令查看数据库版本。 [root@mysql03 ~]# mysql -V mysql Ver 14.14 Distrib 5.7.30, for linux-glibc2.12 (x86_64) using EditLine wrapper

3、创建数据目录,用户。

创建数据存放目录和配置文件存在目录 [root@mysql03 mysql]# mkdir /data/mysql/{3306,conf} -p 注:3306是存放3306端口下的数据目录,conf统一存放数据库配置文件。 添加用户 [root@mysql03 mysql]# useradd -M -s /sbin/nologin mysql 数据目录授权 [root@mysql03 mysql]# chown -R mysql.mysql /data/mysql

4、数据库初始化

数据库数据初始化 [root@mysql03 mysql]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data 显示结果,表示完成数据库的初始化。 [root@mysql03 3306]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data 2020-10-21T07:32:53.611188Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2020-10-21T07:32:54.615541Z 0 [Warning] InnoDB: New log files created, LSN=45790 2020-10-21T07:32:54.760723Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2020-10-21T07:32:54.836833Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a231470b-136f-11eb-9047-fa163e49eccc. 2020-10-21T07:32:54.842611Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2020-10-21T07:32:56.384194Z 0 [Warning] CA certificate ca.pem is self signed. 2020-10-21T07:32:56.725640Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

 MySQL数据库5.7+ 版本初始化命令详解:       mysqld:数据库后台进程          --initialize-insecure:初始化核心参数          --user:用户          --basedir:数据库软件路径:/usr/local/mysql          --datadir:数据存放目录:/data/mysql/3306/data

         --initialize-insecure参数有两种方式,区别如下:

          initialize-insecure:不安全,初始化完成后,登陆数据库可无密码登录;initialize:比较安全,初始化完成后会生成临时随机密码,在第一次登录数据库后,需要立即修改初始密码。

5、mysql配置文件

cat > /data/mysql/conf/my.cnf << EOF [mysqld] user=mysql basedir=/usr/local/mysql datadir=/data/mysql/3306/data socket=/data/mysql/3306/data/mysql.sock [mysql] default-character-set=utf8 collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' character-set-server = utf8 socket=/data/mysql/3306/data/mysql.sock [client] default-character-set=utf8 EOF

6、复制拷贝启动脚本并启动数据库,查看数据进程和监听端口。

数据库启动脚本 [root@mysql03 mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 启动数据库,&表示后台启动 [root@mysql03 mysql]# mysqld --defaults-file=/data/mysql/conf/my.3306.cnf --user=root & 检查数据库进程 [root@mysql03 mysql]# ps -ef|grep mysql mysql 12639 10814 0 Oct21 pts/2 00:00:31 mysqld --defaults-file=/data/mysql/conf/my.3306.cnf --user=root root 15308 11290 0 10:18 pts/3 00:00:00 grep --color=auto 3306 检查数据库端口3306 [root@mysql03 mysql]# netstat -lntup|grep 3306 tcp6 0 0 :::3306 :::* LISTEN 12639/mysqld

7、登陆数据库

登陆数据库时,需要密码验证。 [root@mysql03 conf]# mysql -uroot -p -S /data/mysql/3310/data/mysql.sock Enter password:  2020-10-22T02:26:02.100625Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

数据库登陆方式:

1、本地套接字登陆:mysql -uroot -p -S /data/mysql/3306/data/mysql.sock

2、远程登录:mysql  -h 127.0.0.1   -uroot -p 

三、数据库密码修改

1、因在数据库初始化完成后,登陆数据库时,由于数据库密码问题,需要跳过授权表并重新设置数据库登陆密码。

数据库关闭 [root@mysql03 3306]# mysqladmin -uroot -p123456 -S /data/mysql/3306/data/mysql.sock shutdown 跳过授权表,后台启动数据库 [root@mysql03 3306]# mysqld --defaults-file=/data/mysql/conf/my.3307.cnf --user=root --skip-grant-tables & 登陆数据库,并完成密码修改和授权 [root@mysql03 3306]# mysql -uroot -p -S /data/mysql/3306/data/mysql.sock mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed 修改用户密码 mysql> update user set authentication_string=password('123456') where user='root' and host = 'localhost'; Query OK, 0 rows affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 1 创建用户并授权 mysql> grant all privileges on *.* to 'root'@'%' identified by '123456'; Query OK, 0 rows affected, 1 warning (0.00 sec) 刷新权限 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 查看用户权限列表 mysql> select host,user from mysql.user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 4 rows in set (0.00 sec) mysql>

2、完成用户密码修改和授权后,重新关闭并启动数据库。

关闭数据库 [root@mysql03 3306]# mysqladmin -uroot -p123456 -S /data/mysql/3306/data/mysql.sock shutdown 启动数据库 [root@mysql03 3306]# mysqld --defaults-file=/data/mysql/conf/my.3306.cnf --user=root & 登陆数据库,输入用户名密码 [root@mysql03 3306]# mysql -uroot -p -S /data/mysql/3306/data/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.30 MySQL Community Server (GPL) Copyright (c) 2000, 2020, 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> 查看数据库 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql>

 

至此,数据库安装完成。

最新回复(0)