说在最前面,我也是初学者,可能有些操作不太正确,欢迎提出指导
前言:在腾讯云linux上安装了mysql,出现了几次数据库被删,并留下了一个warnning表,里面留的信息是叫我给它bitcoin它才把数据还给了,我***,我的数据真那么值钱还会被你删。。并且它把我的mysql数据库用户权限给弄无了,我一个root用户连mysql的用户表都看不了。 最后只好重新安装,并且好好设置一番。
被黑原因:密码太简单, 为了图方便给用户 配置了 %
一、卸载
rpm -qa | grep mysql
用以下命令删除查找的结果
rpm -e --nodeps **********
二、删除mysql有关文件
不然用户表这些信息还在,(因为我mysql被攻击了,user表我自己已经没有权限修改了)
//首先用
find / -name mysql
然后用rm -rf删除
三、下载安装
下载(我是直接在~目录下进行下载)
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装
yum -y install mysql-server
这样便安装成功
设置开机启动
chkconfig mysqld on
启动MySQL服务
service mysqld start
四、修改密码
建议密码设置难一点,不要用什么root 或者 123456了
[root@VM-0-11-centos ~]# mysql -u root
/*此处省略*/
mysql> select user,host,password from mysql.user;
+------+----------------+----------+
| user | host | password |
+------+----------------+----------+
| root | localhost | |
| root | vm-0-11-centos | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | vm-0-11-centos | |
+------+----------------+----------+
6 rows in set (0.00 sec)
mysql> set password for root@localhost=password('jiaxin123');
mysql> select user,host,password from mysql.user;
+------+----------------+-------------------------------------------+
| user | host | password |
+------+----------------+-------------------------------------------+
| root | localhost | *A8A6013CE6FD86B8FD811B4F7E2BB72A04A24C76 |
| root | vm-0-11-centos | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | vm-0-11-centos | |
+------+----------------+-------------------------------------------+
6 rows in set (0.00 sec)
mysql> exit
让我的ip能访问,这样我就方便在本地用Navicat建表,不想把post改为%,风险太大。因为我在腾讯云上运行的springboot项目,springboot配置中数据库我可以直接用localhost了。
mysql> create user 'root'@'117.176.185.77' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+----------------+-------------------------------------------+
| user | host | password |
+------+----------------+-------------------------------------------+
| root | localhost | *A8A6013CE6FD86B8FD811B4F7E2BB72A04A24C76 |
| root | vm-0-11-centos | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | vm-0-11-centos | |
| root | 117.176.185.77 | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+------+----------------+-------------------------------------------+
7 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
给我授权
mysql> grant all privileges on *.* to 'root'@'117.176.185.77' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
五、修改默认端口
因为3306太容易被攻击了,我换了一个不常见的
打开/etc/my.cnf
vim /etc/my.cnf
添加语句 port=3506,效果如下
[mysqld]
port=3506
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
最后一步、重启
systemctl restart mysqld