/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
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
查看结果。
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/
复制代码
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
复制代码
/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/usr/local/mysql/data/ --user=mysql
复制代码
chown -R mysql:mysql /usr/local/mysql
。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
。之前添加过就直接退出即可。
vi /root/.bash_profile
打开文件,按 i
进入编辑模式。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的环境变量的基础上再进行修改。Esc
键退出编辑模式,输入 :wq
保存并关闭文件。source /root/.bash_profile
重新执行文件。/etc/init.d/mysqld start
复制代码
出现如下截图所示信息,表示MySQL启动成功。
mysqladmin -u root password
复制代码
提示以下信息:
```
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
```
复制代码
service mysqld stop
mysqld_safe --skip-grant-tables &
复制代码
mysql -uroot -p #-p和密码之间无空格
复制代码
show databases;
查看数据库信息,没有问题运行 \q
退出MySQL。/usr/local/apache/bin/apachectl restart
重启服务器,若提示httpd not running, trying to start
,在输入一次/usr/local/apache/bin/apachectl restart
,没有问题后,基于MySQL的服务就成功了,输入自己服务器的IP进行测试一下。