centos7.4下安装mysql5.7

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/abel004/article/details/82055884

本人环境为centos7.4 64bit

1.检查系统自否自带安装mysql:
rpm -qa | grep mysql

2.有安装的话,先删除卸载。

rpm -e mysql  // 普通删除模式
rpm -e –nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除

3.下载及安装:

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install mysql-server

4.初始化及启动mysql

mysqld –initialize
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld 设置开机启动

5.启动服务器的时候会报如下错误:

Starting mysqld (via systemctl): Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.
[FAILED]

按照提示并不能找到启动失败的真正原因,这是我们要去看mysql的错误日志,首先打开/etc/my.cnf文件查看错误日志文件在哪里。
我的是在/var/log/mysqld.log中,所以我们打开这个错误日志文件,查找错误原因。

[ERROR] InnoDB: .\ibdata1 must be writable

扫描二维码关注公众号,回复: 5030731 查看本文章

解决办法:先删除/var/lib/mysql/ibdata1;

6.重新启动,结果又报如下错误:

mysqld: Can’t find file: ‘./mysql/plugin.frm’ (errno: 13 - Permission denied)

很明显的权限不足错误;
解决办法:

cd /var/lib/mysql; chown -R mysql.mysql *;

7.这下终于启动正常了!MySQL 5.7 在初始安装后(CentOS7 操作系统)会生成随机初始密码,并在 /var/log/mysqld.log 中有记录,可以通过 cat 命令查看,找 password 关键字。

8.实在是忘记root密码了,可以先跳过密码检测;在my.cnf中的[mysqld]下加一行:

skip-grant-tables=1 //设置完密码后删除这一行,重新启动

用mysql -u root无密码登陆后,切换到mysql数据库:

update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';

9.新增一个root权限的新账户:

GRANT ALL PRIVILEGES ON . TO ‘me’@’%’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
flush privileges;

10.关闭防火墙:

systemctl status firewalld.service;
systemctl stop firewalld.service;
systemctl disable firewalld.service; //永久关闭

猜你喜欢

转载自blog.csdn.net/abel004/article/details/82055884