卸载阿里云的mysql_阿里云linux上,记一次mysql重装——卸载,安装 mysql 5.7

上一次的挖矿病毒可是搞惨我了,虽然勉强清掉了,但是不知道为什么mysql后来无法登录了!!!

找了一切办法来解决(from百度),然并卵。

好吧,重装。

1. 备份

备份原来的数据库,里面有我的所有数据库脚本文件,一一拷出来

[root@jun ~]# cd /usr/local/mysql/share/

2.卸载

——参考小黑s

查看安装的mysql:

[root@ ~]# rpm -qa|grep -i mysql

停止mysql服务

[root@jun ~]# /usr/local/mysql/support-files/mysql.server stop

卸载删除mysql组件

rpm -ev mysql-*****

查看mysql文件夹信息

[root@jun ~]# whereis mysql

mysql: /usr/local/mysql /usr/local/mysql/bin/mysql

再 rm -rf 删除mysql对应文件夹

[root@jun ~]# rm -rf /usr/local/mysql /usr/local/mysql/bin/mysql

删除mysql用户名和用户组

[root@jun ~]# more /etc/passwd | grep mysql

[root@jun ~]# more /etc/shadow | grep mysql

[root@jun ~]# more /etc/group | grep mysql

[root@jun ~]# userdel mysql

[root@jun ~]# groupdel mysql

删除配置文件

[root@jun ~]# rm -f /etc/my.cnf /var/log/mysqld.log /var/run/mysqld/

3. 安装

我装的版本是mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

链接:https://pan.baidu.com/s/1ceU6_82jebSumi4hDRkk5Q 密码:rum8(若失效可在下面评论,看到我会更新链接)

1.下载完后上传到linux

2.解压 后移动到/usr/local/mysql下,顺便改名

[root@jun ~]# tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

[root@jun ~]# mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql

3.创建用户组,授权

[root@jun ~]# groupadd mysql

[root@jun ~]# useradd -r -g mysql mysql

[root@jun ~]# chown -R mysql mysql

[root@jun ~]# chgrp -R mysql mysql

4.创建配置文件,添加配置

[root@jun ~]# vim /etc/my.cnf

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

character_set_server=utf8

init_connect='SET NAMES utf8'

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

#skip-grant-tables

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

lower_case_table_names = 1

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections=5000

default-time_zone = '+8:00'

~

~

~

~

~

~

5.安装libaio

[root@jun ~]# yum install libaio

6.添加日志文件,赋权

[root@jun ~]# vim /var/log/mysqld.log

[root@jun ~]# chmod 777 mysqld.log

[root@jun ~]# chown mysql:mysql mysqld.log

[root@jun ~]# cd /var/run/

[root@jun ~]# mkdir mysqld

[root@jun ~]# chmod 777 mysqld

[root@jun ~]# cd mysqld

[root@jun ~]# vim mysqld.pid

[root@jun ~]# chmod 777 mysqld.pid

[root@jun ~]# chown mysql:mysql mysqld.pid

7.初始化:

[root@jun ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US

8.查看初始密码

[root@jun ~]# cat /var/log/mysqld.log

2018-12-04T13:30:57.037965Z 1 [Note] A temporary password is generated for root@localhost: znxw&zw1gvW+

9.启动服务

[root@jun ~]# /usr/local/mysql/support-files/mysql.server start

然后就是登录改密码了 /usr/local/mysql/bin/mysql -uroot -p初始密码

不过我到了这一步是进不去的,我是在/etc/my.cnf的[mysqld]

加了一句skip-grant-tables,取消验证然后再改密码

!!!又被搞了一次,不过这次到了这一步是可以进去的了,直接修改密码:

ALTER USER 'root'@'localhost'IDENTIFIED BY 'mimahere';

过程中遇到过的错误:

1.mysqld文件夹没有加权限

ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).

2.初始化失败

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

[WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize

[ERROR] The data directory needs to be specified.

[ERROR] --initialize specified but the data directory has files in it. Aborting.

3.初始化没成功状态下启动服务,通过service mysqld start

mysqld: Error on realpath() on '/var/lib/mysql-files' (Error 2 - No such file or directory)

[ERROR] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files

[ERROR] Aborting

4.data文件夹没有授权,没办法写

[ERROR] Failed to get stat for directory pointed out by --secure-file-priv

[ERROR] Aborting

5.第一次登录,密码错误,skip-grant-tables解决

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

你可能感兴趣的:(卸载阿里云的mysql)