Linux服务器安装MySQL8.0

服务器安装MySQL 【Linux服务器安装MySQL8.0】服务器使用CentOS7
数据库安装

  1. 检查是否有安装MySQL
    yum list installed | grep mysql

  2. 下载MySQL安装包,这里下载的是8.0
    wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm

  3. 使用yum安装rpm包
    yum -y install mysql80-community-release-el7-2.noarch.rpm

  4. 安装MySQL服务,过程比较慢,需要下载
    yum -y install mysql-community-server

MySQL配置
  1. 启动MySQL服务,记得是mysqld
    systemctl start mysqld.service

  2. 查看MySQL运行状态
    systemctl status mysqld.service● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 三 2021-07-28 16:44:56 CST; 1min 26s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 17913 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 18001 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─18001 /usr/sbin/mysqld7月 28 16:44:47 VM-12-5-centos systemd[1]: Starting MySQL Server... 7月 28 16:44:56 VM-12-5-centos systemd[1]: Started MySQL Server.

  3. 重启/停止服务
    service mysqld restart#重新启动Mysql systemctl stop mysqld.service#停止Mysql

  4. 查看MySQL的root用户初始密码
    grep "password" /var/log/mysqld.log2021-07-28T08:44:50.767029Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: r!FYj6ujDhx%

  5. 登录root用户
    mysql -u root -p

  6. 修改root密码
    # 可以先设置允许简单密码set global validate_password.policy=0; set global validate_password.length=4; # 修改密码ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';

  7. 关闭yum自动更新
    yum -y remove mysql80-community-release-el7-2.noarch

至此MySQL已经安装完成
客户端远程操作数据库
  1. 查看是否开启了3306端口
    我的服务器是腾讯云,所以在控制台配置端口就行了,如果不是可以自行百度

  2. MySQL设置允许远程登录
    USE mysql; UPDATE USER SET host = '%' WHERE USER = 'root'; FLUSH PRIVILEGES;

  3. 然后使用客户端登录即可
不定期更新:Github

    推荐阅读