一、rpm安装
1、安装centos7.9最小化安装(略)
2、下载mysql安装包,如下:
mysql-commercial-common-8.0.30-1.1.el7.x86_64.rpm
mysql-commercial-icu-data-files-8.0.30-1.1.el7.x86_64.rpm
mysql-commercial-libs-8.0.30-1.1.el7.x86_64.rpm
mysql-commercial-server-8.0.30-1.1.el7.x86_64.rpm
mysql-commercial-client-plugins-8.0.30-1.1.el7.x86_64.rpm
mysql-commercial-client-8.0.30-1.1.el7.x86_64.rpm
3、关闭selinux及防火墙,并重启系统
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld
init 6
4.更新Yum源
rm -rf * /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
5、安装需求包
yum install -y perl net-tools
6、卸载冲突软件包
rpm -e postfix;rpm -e mariadb-libs
7、安装软件包
rpm -ivh mysql-commercial-common-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-icu-data-files-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-client-plugins-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-libs-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-client-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-server-8.0.30-1.1.el7.x86_64.rpm
rpm -ivh mysql-commercial-backup-8.0.30-1.1.el7.x86_64.rpm
安装如下:
8、启动mysqld
systemctl start mysqld
systemctl enable mysqld
9、查询mysql密码并登录mysql
grep password /var/log/mysqld.log
mysql -uroot -p'zJNlB<uq&9sk'
10、修改mysql密码为Admin@123
alter user root@localhost identified by 'Admin@123';
11、重新登录mysql
在控制台连接数据库,需要每次输入账号密码,感觉很麻烦,可以通过login-path保存信息,实现快捷登陆
mysql_config_editor set --login-path=client --user=root --port=3306 --password
后期登录mysql 不必再输用户名和密码
mysql_config_editor print
二、绿色安装
1、安装centos7.9最小化安装(略)
2、下载mysql安装包,如下:
mysql-commercial-8.0.30-el7-x86_64.tar.gz
mysql-commercial-backup-8.0.30-el7-x86_64.tar.gz
3、关闭selinux及防火墙,并重启系统
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld
init 6
4.更新Yum源
rm -rf * /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
5、安装需求包
yum install -y perl net-tools
rpm -e postfix;rpm -e mariadb-libs
6、解压软件并设置权限
mkdir /app
useradd mysql
echo password | passwd --stdin mysql
chown -R mysql:mysql /app
配置文件
vim /etc/my.cnf
[mysqld]
basedir=/app/mysql
datadir=/app/mysql/data
socket=/app/mysql/mysql.sock
pid-file=/app/mysql/mysqld.pid
port=3306
log-error=/app/mysql/log/mysqld.log
7、mysql用户登录
cd /app 上传软件包
tar -xvf mysql-commercial-8.0.30-el7-x86_64.tar.gz
mv mysql-commercial-8.0.30-el7-x86_64 mysql
mkdir /app/mysql/log
/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize
启动服务
/app/mysql/bin/mysqld --defaults-file=/app/mysql/my.cnf &
登录
grep password /app/mysql/log/mysqld.log
/app/mysql/bin/mysql -uroot -p'e,2?3)1s#Ge%' -S /app/mysql/mysql.sock
修改密码
alter user root@localhost identified by 'Admin@123';
重新登录mysql
root用户增加系统服务
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
TimeoutSec=0
ExecStart=/app/mysql/bin/mysqld_safe
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false
修改环境变量 mysql用户
vim .bash_profile
在PATH=$PATH:$HOME/.local/bin:$HOME/bin后增加 /app/mysql/bin
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/app/mysql/bin