Debian 下安装 MySQL5.7
一、下载安装程序
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.36-1debian10_amd64.deb-bundle.tar
二、程序解压
tar -xvf mysql-server_5.7.36-1debian10_amd64.deb-bundle.tar
三、依次依赖程序
apt install psmisc libaio1 libnuma1 libatomic1 libmecab2
四、安装MySQL程序(需要按照顺序依次安装)
dpkg -i mysql-common_5.7.35-1debian10_amd64.deb dpkg -i mysql-community-client_5.7.35-1debian10_amd64.deb dpkg -i mysql-client_5.7.35-1debian10_amd64.deb dpkg -i mysql-community-server_5.7.35-1debian10_amd64.deb # 期间会提示输入密码, 并确认密码 dpkg -i mysql-server_5.7.35-1debian10_amd64.deb # 备注:如果执行以上5行命令过程中,出现缺失依赖包,请执行以下命令修复 sudo apt-get -f install
五、修改相关配置
# 1.允许远程访问, 修改bind-address的值为0.0.0.0 # 2.配置数据库默认字符集,新增参数character-set-server=utf8 vim /etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 0.0.0.0 character-set-server=utf8 # 配置客户端默认字符集,新增参数default-character-set=utf8 vim /etc/mysql/conf.d/mysql.cnf default-character-set=utf8 # 执行赋权语句并刷新生效,在进入mysql环境后执行! GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; FLUSH PRIVILEGES; # 查看字符集 show variables like '%character%';
六、配置定时备份任务(定时备份参考示例)
#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin #数据库用户名 db_user=root #数据库密码 db_password=******** #数据库名称 db_name=db_name #备份存放路径 backup_dir=/var/data_backup #备份命名所使用的日期格式 date=$(date +%Y%m%d_%H%M%S) #导出备份 mysqldump -u$db_user -p$db_password $db_name>$backup_dir/$db_name$date.sql #对备份进行压缩: mysqldump -u$db_user -p$db_password $db_name | gzip >$backup_dir/$db_name$date.sql.gz #清理1天前的备份文件及7天前的备份压缩文件 find $backup_dir -mtime +1 -name $db_name"*.sql" -exec rm -rf {} \; find $backup_dir -mtime +7 -name $db_name"*.sql.gz" -exec rm -rf {} \
<< 上一篇
下一篇 >>