当前位置:   article > 正文

centos stream 9 安装mysql8_process: 19387 execstart=/usr/sbin/mysqld $mysqld_

process: 19387 execstart=/usr/sbin/mysqld $mysqld_opts (code=exited, status=

centos stream 9 安装mysql8 步骤


前言

一、mysql 8下载

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

选择相应的mysql 版本已经操作系统版本进行下载,我这边下载是mysql8.0.36

二、mysql 安装

1.解压

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

解压后目录如下:
在这里插入图片描述

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

查看已经安装的mysql (rpm -qa | grep mysql
在这里插入图片描述

3.mysql 初始化

mysqld --initialize; // mysql 初始化
  • 1

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)
  • 1
  • 2

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
#修改默认密码
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)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

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

在这里插入图片描述

#查看服务器防火墙状态
[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 (重启防火墙)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/301264
推荐阅读
相关标签
  

闽ICP备14008679号