Linux-Mysql安装文档
下载官方数据库
个人收集
wget http://cunqi0105-1300757323.cos.ap-shanghai.myqcloud.com/install-pkg/mysql-5.7.32-el7-x86_64.tar.gz
官方下载
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
解压并移动
tar zxvf mysql-5.7.32-el7-x86_64.tar.gz
mv mysql-5.7.32-el7-x86_64 /usr/local/mysql
创建用户组和用户并修改权限
groupadd mysql && useradd -r -g mysql mysql
#创建数据目录并赋予权限
mkdir -p /data/mysql && chown mysql:mysql -R /data/mysql
配置my.cnf
cat <<EOF> /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
max_connections=2048
EOF
初始化数据库
cd /usr/local/mysql/bin/
#初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
#建立软连接
ln -s /usr/local/mysql/bin/mysql* /usr/bin
#查看密码
cat /data/mysql/mysql.err
启动mysql,并更改root 密码
cat <<EOF> /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start mysql
systemctl status mysql
#登录
mysql -u root -p
#更改密码
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
#解决无法使用远程连接数据库
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
数据库自动备份脚本
备份脚本
###################################################
上传到ftp服务器脚本
###################################################
1. 在初始化数据库时出现该错误,是因为缺少numact环境包导致的
yum -y install numactl
本文摘抄或总结其他笔记,笔记不涉及任何商业用途,如果侵权请及时联系处理