阿里云备份快照后MySQL启动不了解决办法

栏目: 数据库 · 发布时间: 6年前

内容简介:阿里云服务器,备份了个快照,备份的时候网站是能用的,然后回滚到这个快照,启动MySQL,报了上面的错,找了网上很多资料都没解决,最后阿里云的工程师解释说,我备份快照的时候就有问题,系统表有问题,mysql.user表不存在,导致数据库无法初始化 。解决办法:暴力的重新安装MySQL,在重新安装之前,记得把数据备份好。提示以下信息:
/etc/init.d/mysqld start
Starting MySQL./usr/local/mysql/bin/mysqld_safe: line 586: /var/lib/mysql/mysqld_safe.pid: No such file or directory
awk: (FILENAME=- FNR=1) warning: error writing standard output (Broken pipe)
2019-01-27T04:16:23.831557Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
The server quit without updating PID file (/var/lib/mysql/i[FAILED]zg7ppyt15vrbkz.pid).
复制代码

阿里云服务器,备份了个快照,备份的时候网站是能用的,然后回滚到这个快照,启动MySQL,报了上面的错,找了网上很多资料都没解决,最后阿里云的工程师解释说,我备份快照的时候就有问题,系统表有问题,mysql.user表不存在,导致数据库无法初始化 。

2019-01-27T10:17:34.838342Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2019-01-27T10:17:34.838856Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-01-27T10:17:34.838945Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-01-27T10:17:34.838956Z 0 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
2019-01-27T10:17:34.838984Z 0 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
2019-01-27T10:17:34.839021Z 0 [Note] Server socket created on IP: '0.0.0.0'.
2019-01-27T10:17:34.839302Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-01-27T10:17:34.839476Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190127 18:17:34
2019-01-27T10:17:34.841275Z 0 [Warning] Failed to open optimizer cost constant tables

2019-01-27T10:17:34.843929Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2019-01-27T10:17:34.843989Z 0 [ERROR] Aborting
复制代码

解决办法:暴力的重新安装MySQL,在重新安装之前,记得把数据备份好。

编译安装MySQL

  1. 依次执行以下命令检查系统中是否存在使用rpm安装的 MySQL 或者MariaDB。

    rpm -qa | grep mysql
    rpm -qa | grep mariadb
    复制代码

    如果已经安装,则运行以下任一个命令删除。

    rpm -e 软件名    #注意:这里的软件名必须包含软件的版本信息,如rpm -e mariadb-libs-5.5.52-1.el7.x86_64。一般使用此命令即可卸载成功。
    rpm -e --nodeps 软件名   #卸载不成功时使用此命令强制卸载
    复制代码

    卸载后,再用 rpm -qa|grep mariadb 或者 rpm -qa|grep mysql 查看结果。

  2. 依次运行以下命令安装 MySQL,之前有安装过直接覆盖就行,一路回车。

    yum install -y libaio-*                         #安装依赖
    mkdir -p /usr/local/mysql
    cd /usr/local/src
    wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz 
    tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
    mv mysql-5.7.17-linux-glibc2.5-x86_64/* /usr/local/mysql/
    复制代码
  3. 依次运行以下命令建立mysql组和用户,并将mysql用户添加到mysql组。之前添加过可能存在,直接回车。

    groupadd mysql
    useradd -g mysql -s /sbin/nologin mysql
    复制代码
  4. 运行命令初始化MySQL数据库。

    /usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/usr/local/mysql/data/ --user=mysql
    复制代码
  5. 更改MySQL安装目录的属性: chown -R mysql:mysql /usr/local/mysql

  6. 依次运行以下命令设置开机自启动。

    cd /usr/local/mysql/support-files/
    cp mysql.server  /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld             # 添加执行权限
    vim /etc/rc.d/rc.local
    复制代码

    在 rc.local 文件中添加 /etc/init.d/mysqld start 。之前添加过就直接退出即可。

  7. 设置环境变量。

    1. 运行 vi /root/.bash_profile 打开文件,按 i 进入编辑模式。

    2. PATH=$PATH:$HOME/bin:/usr/local/apache/bin 修改为 PATH=$PATH:$HOME/bin:/usr/local/apache/bin:/usr/local/mysql/bin:/usr/local/mysql/bin 。之前如果修改过就直接退出。

      说明:此处是在编译安装 Apache的环境变量的基础上再进行修改。

    3. Esc 键退出编辑模式,输入 :wq 保存并关闭文件。

    4. 运行 source /root/.bash_profile 重新执行文件。

  8. 启动 MySQL 数据库。

    /etc/init.d/mysqld start
    复制代码

    出现如下截图所示信息,表示MySQL启动成功。

    阿里云备份快照后MySQL启动不了解决办法
  9. 修改MySQL的root用户密码:初始化后MySQL为空密码可直接登录,为了保证安全性需要修改MySQL的root用户密码。运行以下命令,并按界面提示设置密码。

    mysqladmin -u root password
    复制代码

提示以下信息:

``
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
```
复制代码
  1. 关闭数据库并执行
service mysqld stop
mysqld_safe --skip-grant-tables &
复制代码
  1. 再次测试登录MySQL数据库。

    mysql -uroot -p #-p和密码之间无空格
    复制代码
    阿里云备份快照后MySQL启动不了解决办法
  2. 输入 show databases; 查看数据库信息,没有问题运行 \q 退出MySQL。

  3. 输入 /usr/local/apache/bin/apachectl restart 重启服务器,若提示 httpd not running, trying to start ,在输入一次 /usr/local/apache/bin/apachectl restart ,没有问题后,基于MySQL的服务就成功了,输入自己服务器的IP进行测试一下。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Trading and Exchanges

Trading and Exchanges

Larry Harris / Oxford University Press, USA / 2002-10-24 / USD 95.00

This book is about trading, the people who trade securities and contracts, the marketplaces where they trade, and the rules that govern it. Readers will learn about investors, brokers, dealers, arbit......一起来看看 《Trading and Exchanges》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码