1.下載rpm文件
https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
2.上傳到centos7中
3.解壓
tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar -C ./mysql8
4.進入mysql8文件:
1.安裝common rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm --nodeps --force 2.安裝 libs rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm --nodeps --force 3.安裝client rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm --nodeps --force 4.安裝server rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps --force
5.對安裝路徑進行授權
chown mysql:mysql /var/lib/mysql -R;
mkdir /var/log/mysql
chown mysql:mysql /var/log/mysql -R;
6.初始化
mysqld --initialize;
7.啓動報錯
systemctl start mysqld.service; Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
錯誤信息:
2022-06-25T11:53:37.340412Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 45584 2022-06-25T11:53:37.353199Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-06-25T11:53:38.176035Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-06-25T11:53:38.789384Z 0 [Warning] [MY-013829] [Server] Missing data directory for ICU regular expressions: /usr/lib64/mysql/private/. 2022-06-25T11:53:39.129896Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )GK1ta/8=qqh 2022-06-25T11:54:06.619363Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 45672 2022-06-25T11:54:06.677878Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 84256f11-f47d-11ec-8275-0050563fd5e7. mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied) 2022-06-25T11:54:06.677969Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13) 2022-06-25T11:54:06.677979Z 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-06-25T11:54:06.678018Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-06-25T11:54:06.678408Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28) MySQL Community Server - GPL.
解決
chmod -R 777 /var/lib/mysql/auto.cnf
繼續報錯:
2022-06-25T12:11:48.382457Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 46057 2022-06-25T12:11:48.389019Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-06-25T12:11:48.389071Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable 2022-06-25T12:11:48.389085Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable 2022-06-25T12:11:48.389106Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine 2022-06-25T12:11:48.389177Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed. 2022-06-25T12:11:48.389210Z 0 [ERROR] [MY-010119] [Server] Aborting 2022-06-25T12:11:48.389711Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28) MySQL Community Server - GPL.
應該是沒有權限解決辦法,重寫執行
chown mysql:mysql /var/lib/mysql -R;
啓動
systemctl start mysqld.service;
檢查狀態
[root@rocketmq02 mysql8]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-06-25 20:13:31 CST; 1min 12s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 46133 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 46161 (mysqld) Status: "Server is operational" Tasks: 37 CGroup: /system.slice/mysqld.service └─46161 /usr/sbin/mysqld Jun 25 20:13:28 rocketmq02 systemd[1]: Starting MySQL Server... Jun 25 20:13:31 rocketmq02 systemd[1]: Started MySQL Server.
8.修改密碼:
找到初始密碼:
cat /var/log/mysqld.log | grep password
執行
mysql -u root -p 進行登錄
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
報錯:
修改密碼限制,先修改一次密碼,如下:
否則你會發現,你無法修改,密碼的難度的設置
顯示當前設置
修改密碼長度:
set global validate_password.length=4;
修改密碼等級:
set global validate_password.policy=LOW;
設置chek_name
set global validate_password.check_user_name=OFF;
再次查看:
再次修改密碼:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
9.設置遠程訪問:
create user 'root'@'%' identified with mysql_native_password by 'root'; grant all privileges on *.* to 'root'@'%' with grant option; flush privileges;
10.測試:
11.防火牆放開
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent #重啓防火牆 sudo firewall-cmd --reload