CentOS stream 9 安装MySQL8

CentOS stream 9 安装mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar

安装版本

下载地址:mysql-8.0.32-1.el9.x86_64.rpm-bundle.tar

解压文件

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

安装

  • 需要注意按照对应顺序安装
rpm -ivh mysql-community-common-8.0.32-1.el9.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.32-1.el9.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.32-1.el9.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.32-1.el9.x86_64.rpm --nodeps --force

检查安装

rpm -qa | grep mysql
mysql-community-common-8.0.32-1.el9.x86_64
mysql-community-libs-8.0.32-1.el9.x86_64
mysql-community-client-8.0.32-1.el9.x86_64
mysql-community-server-8.0.32-1.el9.x86_64

初始化mysqld

mysqld --initialize

启动mysql

systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details.
  • 注意,这里启动会报错,查看状态结果
systemctl status mysqld.service
× mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Thu 2022-11-17 00:14:54 CST; 4min 4s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 38423 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
    Process: 38450 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
   Main PID: 38450 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete"
      Error: 13 (Permission denied)
        CPU: 881ms

11月 17 00:14:52 localhost.localdomain systemd[1]: Starting MySQL Server...
11月 17 00:14:54 localhost.localdomain systemd[1]: mysqld.service: Main process exited, code=exi>
11月 17 00:14:54 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code>
11月 17 00:14:54 localhost.localdomain systemd[1]: Failed to start MySQL Server.
  • 查看日志
cat /var/log/mysqld.log
...
mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)
2022-11-16T16:14:54.114480Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)
2022-11-16T16:14:54.114485Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2022-11-16T16:14:54.114512Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-11-16T16:14:54.114653Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32)  MySQL Community Server - GPL.

这里提示/var/lib/mysql/auto.cnf没有权限

cd /var/lib/mysql
ls -al
总用量 78276
drwxr-x--x.  7 mysql mysql     4096 11月 17 00:14  .
drwxr-xr-x. 57 root  root      4096 11月 17 00:10  ..
-rw-r-----.  1 root  root        56 11月 17 00:13  auto.cnf
-rw-r-----.  1 mysql mysql        0 11月 17 00:14  binlog.index
-rw-------.  1 root  root      1705 11月 17 00:13  ca-key.pem
-rw-r--r--.  1 root  root      1112 11月 17 00:13  ca.pem
...

查看/var/lib/mysql目录,发现有的文件时root权限,有的是mysql权限。

  • 修改权限
chown -R mysql:mysql /var/lib/mysql
chmod -R 777 /var/lib/mysql
ls -al
总用量 78276
drwxrwxrwx.  7 mysql mysql     4096 11月 17 00:14  .
drwxr-xr-x. 57 root  root      4096 11月 17 00:10  ..
-rwxrwxrwx.  1 mysql mysql       56 11月 17 00:13  auto.cnf
-rwxrwxrwx.  1 mysql mysql        0 11月 17 00:14  binlog.index
-rwxrwxrwx.  1 mysql mysql     1705 11月 17 00:13  ca-key.pem
-rwxrwxrwx.  1 mysql mysql     1112 11月 17 00:13  ca.pem
-rwxrwxrwx.  1 mysql mysql     1112 11月 17 00:13  client-cert.pem
-rwxrwxrwx.  1 mysql mysql     1705 11月 17 00:13  client-key.pem
-rwxrwxrwx.  1 mysql mysql   196608 11月 17 00:13 '#ib_16384_0.dblwr'
-rwxrwxrwx.  1 mysql mysql  8585216 11月 17 00:13 '#ib_16384_1.dblwr'
-rwxrwxrwx.  1 mysql mysql     5985 11月 17 00:13  ib_buffer_pool
-rwxrwxrwx.  1 mysql mysql 12582912 11月 17 00:13  ibdata1
drwxrwxrwx.  2 mysql mysql     4096 11月 17 00:13 '#innodb_redo'
drwxrwxrwx.  2 mysql mysql        6 11月 17 00:13 '#innodb_temp'
drwxrwxrwx.  2 mysql mysql      143 11月 17 00:13  mysql
-rwxrwxrwx.  1 mysql mysql 25165824 11月 17 00:13  mysql.ibd
drwxrwxrwx.  2 mysql mysql     8192 11月 17 00:13  performance_schema
-rwxrwxrwx.  1 mysql mysql     1705 11月 17 00:13  private_key.pem
-rwxrwxrwx.  1 mysql mysql      452 11月 17 00:13  public_key.pem
-rwxrwxrwx.  1 mysql mysql     1112 11月 17 00:13  server-cert.pem
-rwxrwxrwx.  1 mysql mysql     1705 11月 17 00:13  server-key.pem
drwxrwxrwx.  2 mysql mysql       28 11月 17 00:13  sys
-rwxrwxrwx.  1 mysql mysql 16777216 11月 17 00:13  undo_001
-rwxrwxrwx.  1 mysql mysql 16777216 11月 17 00:13  undo_002
  • 启动mysql
systemctl start mysqld.service
ps -ef | grep mysql
mysql      38659       1  9 00:39 ?        00:00:00 /usr/sbin/mysqld
root       38712    8273  0 00:39 pts/1    00:00:00 grep --color=auto mysql

查看临时密码

cat /var/log/mysqld.log | grep password
2022-11-16T16:13:36.933150Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: i!pqjBuRu4rO
mysql -uroot -p'i!pqjBuRu4rO'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)

远程访问

mysql> create user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)

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

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
  • 关闭防火墙
systemctl stop firewalld

遇到问题

Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ae_expert.crdcfg_pin.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
  • 删除sql_mode中的ONLY_FULL_GROUP_BY
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

结束~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值