需要帮客户搭建一个WodPress+WooCommerce 的自建站,服务器选择的是阿里云ECS云服务器,机房是美国硅谷,操作系统为Centos7.9,WordPress准备使用Nginx + PHP + Mysql8.0, 首先安装Mysql8.0,安装Mysql有多种方式,之前都是使用yum命令,这次使用RPM方式, 这篇记录一下在Centos使用rpm安装mysql8的过程。
一、环境准备
操作系统:centos7.9
卸载系统自带的mysql记录
[root@xxx bin]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-8.el6_8.x86_64
[root@xxx bin]# yum remove mysql-libs
依赖检查、设置权限
[root@iZrj9ankp0baz585nmt42hZ home]# rpm -qa|grep libaio
[root@iZrj9ankp0baz585nmt42hZ home]# rpm -qa|grep net-tools
[root@iZrj9ankp0baz585nmt42hZ home]# chmod -R 777 /tmp
二、下载Mysql指定版本
下载mysql指定版本:
进入mysql官网下载页面https://dev.mysql.com/downloads/, 点击MySQL Community Server, 在General Availability (GA) Releases 标签下,选择Mysql版本 8.0.36,操作系统对应Red Hat Enterprise Linux,下载rpm bundle全量包。
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
三、RPM安装Mysql
按顺序执行以下命令:
rpm -ivh mysql-community-common-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
安装过程
[root@xx home]# rpm -ivh mysql-community-common-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.36-1.e################################# [100%]
[root@xx home]# rpm -ivh mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-plugins-8.################################# [100%]
[root@xx home]# rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.36-1.el7################################# [100%]
[root@xx home]# rpm -ivh mysql-community-client-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.36-1.e################################# [100%]
[root@xx home]# rpm -ivh mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-icu-data-files-8.################################# [100%]
[root@xx home]# rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.36-1.e################################# [100%]
验证安装结果:
[root@xx home]# mysql --version
mysql Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)
[root@xx home]# rpm -qa | grep -i mysql
mysql-community-common-8.0.36-1.el7.x86_64
mysql-community-icu-data-files-8.0.36-1.el7.x86_64
mysql-community-client-plugins-8.0.36-1.el7.x86_64
mysql-community-client-8.0.36-1.el7.x86_64
mysql-community-server-8.0.36-1.el7.x86_64
mysql-community-libs-8.0.36-1.el7.x86_64
服务初始化、查看密码
[root@xx home]# mysqld --initialize --user=mysql
[root@xx home]# cat /var/log/mysqld.log
2024-04-09T04:39:24.088952Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.36) initializing of server in progress as process 12223
2024-04-09T04:39:24.096501Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-04-09T04:39:25.139975Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-04-09T04:39:26.482344Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hyrdK;/(=6?q
启动Mysql,查看状态
[root@iZrj9ankp0baz585nmt42hZ home]# systemctl start mysqld.service
[root@iZrj9ankp0baz585nmt42hZ home]# systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2024-04-09 12:41:20 CST; 3s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 12316 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 12340 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─12340 /usr/sbin/mysqld
启动:systemctl start mysqld.service
关闭:systemctl stop mysqld.service
重启:systemctl restart mysqld.service
查看状态:systemctl status mysqld.service
设置启动: systemctl enable mysqld.service
四、Mysql登录
首次登录:
[root@iZrj9ankp0baz585nmt42hZ home]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.36
Copyright (c) 2000, 2024, 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>
修改初始密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxx';
设置远程登录:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select Host,User from user;
+-----------+------------------+
| Host | User |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
五、配置修改
Linux下大小写规则,Mysql在Linux环境下,数据库、表名、表别名、变量名是严格区分大小写的,如果需要设置为大小写不敏感,在Mysql5.7版本下 需要修改配置文件 my.conf ,设置 lower_case_table_names=1
[root@xx home]# vi /etc/my.cnf
[mysqld]
lower_case_table_names=1
在Mysql8.0 下,需要做以下步骤:
- 停止Mysql8.0 服务, systemctl stop mysqld
- 删除/var/lib/mysql 下所有文件
- 重新执行 mysqld –initialize
- 启动mysql
- 操作之前做好备份
以上就已经在阿里云ECS云服务器上安装Mysql8.0的步骤。
原创文章,作者:zhuji001,如若转载,请注明出处:https://www.zhuji66.com/aliyun-ecs-install-mysql8-use-rpm/
本站分享VPS和云服务器信息均来源于网络,如有侵权请邮箱联系zhuji66com@yeah.net。本站不销售任何产品,如遇问题请联系对应客服。