无网络环境下安装mysql
shell 安装脚本:
#!/bin/bash
delete_mariadb(){
systemctl stop mysqld
systemctl stop mysql
# yum remove mariadb* -y
mariadb_list=`rpm -qa |grep mariadb`
for i in $mariadb_list
do
yum remove $i -y
done
# yum remove mysql* -y
mysql_list=`rpm -qa |grep mysql`
for i in $mysql_list
do
yum remove $i -y
done
rm -rf /etc/my.cnf
}
install_mysql(){
tar_local=mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
mkdir /opt/mysql
rm -rf /opt/mysql/*.rpm
tar -xvf $tar_local -C /opt/mysql
cd /opt/mysql
yum install -y mysql-community-common-5.7.32-1.el7.x86_64.rpm
yum install -y mysql-community-libs-5.7.32-1.el7.x86_64.rpm
yum install -y mysql-community-client-5.7.32-1.el7.x86_64.rpm
yum install -y mysql-community-server-5.7.32-1.el7.x86_64.rpm
}
alt_mycanf(){
#mv /etc/my.cnf /etc/my.cnf.bak
cp -rf /opt/mysql_install/my.cnf /etc/
systemctl restart mysqld;systemctl enable mysqld;systemctl status mysqld
}
delete_mariadb
install_mysql
alt_mycanf
#报错处理
#[ERROR] InnoDB: Operating system error number 13 in a file operation.
#[ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
#[ERROR] InnoDB: os_file_get_status() failed on './ibdata1'. Can't determine file permissions
#[ERROR] InnoDB: Plugin initialization aborted with error Generic error
#[ERROR] Plugin 'InnoDB' init function returned error.
#[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
#[ERROR] Failed to initialize builtin plugins.
#[ERROR] Aborting
# ↓↓↓↓↓↓
#[错误] InnoDB:文件操作中的操作系统错误号13。
#[错误] InnoDB:该错误意味着mysqld没有访问该目录的权限。
#[错误] InnoDB: os_file_get_status()在上失败。/ibdata1。无法确定文件权限
#[错误] InnoDB:插件初始化中止,出现错误一般错误
#[错误]插件“InnoDB”初始化函数返回错误。
#[错误]插件“InnoDB”注册为存储引擎失败。
#[错误]初始化内置插件失败。
#[错误]中止
#解决方案
#[root@localhost ~]# getenforce //查看selinux状态
#Enforcing
#[root@localhost ~]# setenforce 0 //临时关闭selinux,重启后失效
# cat /etc/selinux/config
#SELINUX=disabled //永久关闭
my.cnf:
可设置log,安装失败时可以帮助排查错误
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/data/mysql/mysqld/mysqld.pid
socket=/data/mysql/mysql.sock
[client]
socket=/data/mysql/mysql.sock
# Add UTF-8
# character_set=utf8
# init_connect='SET NAMES utf8'
首次登陆mysql
mysql -uroot -p
首次随即密码查询
cd /data/mysql
cat /mysqld.log
2021-11-24T06:13:09.449379Z 1 [Note] A temporary password is generated for root@localhost: xxxxxx
更改密码,报错密码过于简单
set global validate_password_length=4;
set global validate_password_policy=0;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxx';
终端连接取消localhost 限制
mysql -uroot -pxxxx
use mysql;
select user,host from user;
update user set host = '%' where user='root';
# 重启数据库
service mysqld restart;