当主磁盘空间不够,MySQL 5.7安装时指定数据目录

操作系统:CentOS 7/8
MySQL版本:MySQL Community Server 5.7.34

过程:
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.34-1.el7.x86_64.rpm-bundle.tar

yum install libaio #CentOS 8 用dnf,CentOS 7用yum
yum install libncurses* #CentOS 8需要
yum install net-tools #CentOS 7需要

rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm

mkdir /data/mysql/
chown mysql:mysql /data/mysql/
chmod 750 /data/mysql/
/usr/sbin/mysqld --initialize --user=mysql --datadir=/data/mysql/

cd /etc/
cp my.cnf my.cnf.bak
vi my.cnf

[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock

[client]
socket=/data/mysql/mysql.sock

semanage fcontext -a -t mysqld_db_t "/data/mysql(/.*)?" #启用了SELinux的必须
restorecon -Rv /data/mysql #启用了SELinux的必须

service mysqld restart
----------------------------#至此安装完成,以下是初始化配置

grep 'temporary password' /var/log/mysqld.log #获取临时密码
mysql -u root -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> CREATE USER 'username'@'host' IDENTIFIED BY 'password';
mysql> GRANT ALL ON *.* TO 'username'@'%';
mysql> exit

----------------------------------#开启防火墙例外
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

posted @ 2021-10-12 15:23  客家岸田  阅读(309)  评论(2编辑  收藏  举报
联系和建议: antield[at]126.com