欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CentOS7内网使用rpm方式安装MySQL5.6数据库

程序员文章站 2022-05-26 23:40:34
...

CentOS7内网使用rpm方式安装MySQL5.6数据库

生成环境为内网环境,无法通过互联网使用Yum方式安装MySQL数据库时,可以参考本文进行安装。

系统环境

当前演示操作系统为最小化安装的CentOS 7.6。

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

准备工作

1、操作系统版本对应的ISO镜像文件(如CentOS-7-x86_64-DVD-1810.iso),用以配置本地Yum源;
2、在MySQL官网下载MySQL5.6 RPM安装包(如MySQL-5.6.43-1.el7.x86_64.rpm-bundle.tar);
3、将ISO镜像文件及数据库安装包上传至服务器。

配置本地Yum源

# 挂载ISO文件
mkdir /media/iso
mount -o loop -t iso9660 /root/CentOS-7-x86_64-DVD-1810.iso /media/iso

# 备份配置文件
mkdir ~/yum.repos.d_bak
mv /etc/yum.repos.d/* ~/yum.repos.d_bak/

# 创建本地Yum源配置文件
cat > /etc/yum.repos.d/CentOS-Local.repo <<EOF
[CentOS-Local]
name=CentOS-Local
baseurl=file:///media/iso
enabled=1
gpgcheck=0
EOF

# 刷新Yum缓存
yum clean all
yum repolist all

安装MySQL 5.6

# 移除所有已安装的MariaDB相关软件包
rpm -qa | grep maria | xargs yum remove -y

# 安装所需的依赖
yum -y install autoconf libaio openssl-devel perl-JSON

# 解压上传到服务器的tar压缩包
tar -xvf MySQL-5.6.43-1.el7.x86_64.rpm-bundle.tar

# 安装MySQL 5.6
rpm -ivh MySQL-server-5.6.43-1.el7.x86_64.rpm MySQL-devel-5.6.43-1.el7.x86_64.rpm MySQL-client-5.6.43-1.el7.x86_64.rpm

# 创建MySQL数据存放目录
mkdir -p /data/mysql

# 修改配置文件
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
echo "character-set-server=utf8" >> /etc/my.cnf
echo "datadir=/data/mysql" >> /etc/my.cnf
echo "max_connections=1000" >> /etc/my.cnf

# 初始化MySQL
/usr/bin/mysql_install_db
chown -Rf mysql:mysql /data/mysql

# 启动MySQL、查看MySQL状态、配置开机自启动
systemctl start mysql
systemctl status mysql
chkconfig mysql on
chkconfig --list | grep mysql

登录MySQL并设置密码

此时使用root用户登录MySQL是不需要密码的,登录数据库设置root密码。

[[email protected] ~]# mysql -uroot -p
Enter password: #回车即可
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.43 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> set password=password('[email protected]');
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye
[[email protected] ~]# mysql -uroot [email protected]
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.43 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>

允许MySQL数据库root用户远程登录及本地登录

[[email protected] ~]# mysql -uroot [email protected]
mysql> use mysql;
mysql> update user set host='%' where user='root' and host='localhost';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by '[email protected]' with grant option;
mysql> flush privileges;
mysql> exit
相关标签: MySQL