centos stream 9 安装mysql8

centos stream 9 安装mysql8 步骤

文章目录

  • centos stream 9 安装mysql8 步骤
  • 前言
  • 一、mysql 8下载
    • 1.进入mysql 官网下载页面:[https://dev.mysql.com/downloads/mysql/](https://dev.mysql.com/downloads/mysql/)
  • 二、mysql 安装
    • 1.解压
    • 2.安装(依序安装)
    • 3.mysql 初始化
    • 4.查看mysql 初始密码(`cat /var/log/mysqld.log | grep password`)
    • 5.修改mysql用户默认密码
    • 6.使用navicat for mysql 进行远程链接


前言

一、mysql 8下载

1.进入mysql 官网下载页面:https://dev.mysql.com/downloads/mysql/

centos stream 9 安装mysql8_第1张图片

二、mysql 安装

1.解压

tar -xvf   mysql-8.0.36-1.el9.x86_64.rpm-bundle

解压后目录如下:
centos stream 9 安装mysql8_第2张图片

2.安装(依序安装)

1.rpm -ivh mysql-community-common-8.0.36-1.el9.x86_64.rpm
2.rpm -ivh mysql-community-client-plugins-8.0.36-1.el9.x86_64.rpm
3.rpm -ivh mysql-community-libs-8.0.36-1.el9.x86_64.rpm
4.rpm -ivh mysql-community-client-8.0.36-1.el9.x86_64.rpm
5.rpm -ivh mysql-community-icu-data-files-8.0.36-1.el9.x86_64.rpm
6.rpm -ivh mysql-community-server-8.0.36-1.el9.x86_64.rpm

查看已经安装的mysql (rpm -qa | grep mysql
centos stream 9 安装mysql8_第3张图片

3.mysql 初始化

mysqld --initialize; // mysql 初始化

4.查看mysql 初始密码(cat /var/log/mysqld.log | grep password

[root@localhost mysql]# cat /var/log/mysqld.log | grep password
2024-01-29T02:54:28.654261Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: KKgQ*e=ra5Ld(密码是 KKgQ*e=ra5Ld)

5.修改mysql用户默认密码

[root@localhost lib]# mysql  -uroot -p"KKgQ*e=ra5Ld"
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
# 使用命令 systemctl status mysqld.service 查看mysql 状态
[root@localhost mysql]# systemctl status mysqld.service
× mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Mon 2024-01-29 11:01:36 CST; 38s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 38439 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    Process: 38466 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
   Main PID: 38466 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete"
      Error: 13 (权限不够)
        CPU: 1.143s

1月 29 11:01:35 localhost.localdomain systemd[1]: Starting MySQL Server...
1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Main process exited, code=exited, status=1/FAILURE
1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code'.
1月 29 11:01:36 localhost.localdomain systemd[1]: Failed to start MySQL Server.
1月 29 11:01:36 localhost.localdomain systemd[1]: mysqld.service: Consumed 1.143s CPU time.
# 查看mysql 安装目录权限(默认安装在 /var/lib/mysql)
[root@localhost lib]# ll
drwxr-x--x.  7 mysql          mysql          4096  1月 29 11:01 mysql
[root@localhost lib]# chmod -R 777 mysql
drwxrwxrwx.  7 mysql          mysql          4096  1月 29 11:01 mysql
#重新启动mysql
[root@localhost lib]# systemctl start mysqld.service
#登录
[root@localhost lib]# mysql  -uroot -p"KKgQ*e=ra5Ld"
#开机自启动mysql
[root@localhost lib]#  systemctl enable mysqld.service
#修改默认密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)
#修改运行远程登录访问
mysql> create user 'han'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'han'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

6.使用navicat for mysql 进行远程链接

centos stream 9 安装mysql8_第4张图片

#查看服务器防火墙状态
[root@localhost ~]#  systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)
     Active: active (running) since Mon 2024-01-29 10:33:29 CST; 47min ago
       Docs: man:firewalld(1)
   Main PID: 878 (firewalld)
      Tasks: 2 (limit: 10762)
     Memory: 8.0M
        CPU: 378ms
     CGroup: /system.slice/firewalld.service
             └─878 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid

1月 29 10:33:29 localhost systemd[1]: Starting firewalld - dynamic firewall daemon...
1月 29 10:33:29 localhost systemd[1]: Started firewalld - dynamic firewall daemon.
#关闭防火墙(开发版本,生产版本可以使用开放端口的命令)
[root@localhost ~]#  systemctl stop firewalld
[root@localhost ~]#  systemctl disable firewalld (永久关闭)
#开放端口(防火墙不关闭的状态下)
[root@localhost ~]# firewall-cmd --zone=public --permanent --add-port=3306/tcp (添加mysql 端口)
success
[root@localhost ~]# systemctl restart firewalld (重启防火墙)

centos stream 9 安装mysql8_第5张图片

你可能感兴趣的:(centos,mysql)