1、安装mysql5.7
(1) 正常安装
[root@BrianZhu /]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@BrianZhu /]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@BrianZhu /]# yum -y install mysql-community-server
(2) 如果上面安装很慢,要么切yum源,要么缓存rpm包
如果云主机下载很慢(需要没有安装过mysql干净的系统,如果有mysql会下载失败)(多试几次)
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# yum install --downloadonly --downloaddir=./ mysql-community-server
# 将下载的依赖包打包到新的环境
2、启动mysql
(1) 启动mysql
systemctl start mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service
(2) 查看默认密码(#Vy?fk?uo7,1)
# grep "password" /var/log/mysqld.log
2021-08-01T02:17:57.056709Z 1 [Note] A temporary password is generated for root@localhost: #Vy?fk?uo7,1
如果找不到密码就破解
3、破解mysql密码
0、一般情况通过日志就能查看到mysql的秘密
# tail -f /var/log/mysql.log
[Note] A temporary password is generated for root@localhost: VwshKuCya8-=
1、修改my.cnf
[mysqld]
skip-grant-tables #跳过授权表
2、重启mysql
/etc/init.d/mysqld restart
3、空密码登录mysql
mysql -uroot -p
4、先更新一次密码
mysql> UPDATE mysql.user SET authentication_string=password('wenqiang123') WHERE User='root'; # 新版
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4 Changed: 0 Warnings: 0
mysql> flush privileges; # 必须做
5、如果报错再次修改密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Clouddeep@8890'; # 密码复杂度必须要高
6、将my.cnf中的skip-grant-tables 删除
7、重启mysql
4、登录mysql
# mysql -uroot -p -h 127.0.0.1 -P 3306
5、创建数据库并授权其他用户登录(如果可以正常创建数据库这一步不用做)
(1) 这个版本需要升级mysql
# mysql_upgrade -uroot -p --force
# systemctl restart mysqld # 一定要重启
(2) 创建数据库
mysql> create database rdc_manager;
(3) 为用户并授权
mysql> grant all privileges on rdc_manager.* to clouddeep@'10.4.7.%' identified by 'Clouddeep@8890';
Query OK, 0 rows affected, 1 warning (0.00 sec)
6、定期备份mysql
# cat mysql_bak.sh
#!/bin/bash
user='root'
passwd='Clouddeep@8890'
#当前时间
date=`date -d "today" +"%Y%m%d"`
#备份的sql文件存放路径
back_path=/project/backup/mysql_backup
# 备份的数据库名称
db_name='rdc_manager'
if [[ ! -d ${back_path} ]]
then
mkdir -p ${back_path}
fi
# backup
mysqldump -u${user} -p${passwd} --opt --default-character-set=utf8 -R --hex-blob --flush-logs ${db_name} > /${back_path}/rdc_manager-${date}.sql
# delete
find ${back_path} -name "*.sql" -mtime +90|xargs rm -rf
# crontab -l
30 01 * * * /bin/sh /home/shell/mysql_bak.sh