Centos7下MySQL 8.0 安装相关基础问题


  1. yum -y install mysql mysql-server

    • 提示已经安装mariadb 不再安装mysql
    • 提示没有在yum 库中找到mysql-server :
      • 需要首先从mysql官网下载npm包到本地:wget https://mysql.com/get/mysql**-community-release*****.noarch.rpm(具体的mysql版本),参见mysql 官方yum库
      • yum install mysql**-community-release*****.noarch.rpm
      • yum install mysql-server
  2. 确认mysqld服务是否正确运行。尝试登陆时,若异常可能报错Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

    • 查看mysql 3306端口是否打开:lsof -i:3306或者netstat -ntpl |grep 3306

    • 查看mysql服务是否启动service mysqld status 或者 systemctl status mysqld

    • 若上述报错,确认/etc/init.d目录下是否含有msyqld服务(init.d 目录中存放的是一系列系统服务的管理(启动或停止)脚本),若没有

      • 使用find / -name msyqld
      • 将上述找到的目录 复制到/etc/init.d
      • 重启mysql 服务 systemctl restart msyqld , systemctl status mysqld
    • 初次使用root用户以空密码登陆时报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 参考链接

      • 原因:root用户空密码只适用于5.7以下版本

      • 对于5.7以上的版本

        The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file

        查看方法grep 'temporary password' /var/log/mysqld.log

  3. 首次成功登陆后修改root密码ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!'