官网或镜像站下载二进制包,以mysql5.6为例
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 -d /data/mysql mysql
#可选做,后面的脚本mysql_install_db可自动生成此目录
mkdir /data/mysql
chown mysql:mysql /data/mysql
tar xf mysql-VERSION-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -sv mysql-VERSION mysql
chown -R root:root /usr/local/mysql/
cd /usr/local/mysql
cp -b support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
#mysql语句块中添加以下三个选项
[mysqld]
datadir = /data/mysql
innodb_file_per_table = on #在mariadb5.5以上版的是默认值,可不加
skip_name_resolve = on #禁止主机名解析,建议使用
cd /usr/local/mysql/
./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
#如果有对应的service 文件可以执行下面
cp /usr/local/mysql/support-files/systemd/mariadb.service
/usr/lib/systemd/system/
systemctl daemon-reload
systemctl enable --now mariadb
echo ‘PATH=/user/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
/user/local/mysql/bin/mysql_secure_installation
原文:https://www.cnblogs.com/askword/p/14853545.html