在Alibaba Cloud Linux上安装MySQL 8.2创新版

阿里云为ECS提供最新版本的是Alibaba Cloud Linux 3系统(3.2104 LTS 64位),根据Release Notes可以确定这是一个“CentOS 8、RHEL 8”兼容版,开始安装吧。

1. 下载,并添加MySQL官方Yum仓库

下载时选择Red Hat Enterprise Linux 8版本即可。

# 下载,Centos 8版本:
wget https://dev.mysql.com/get/mysql80-community-release-el8-9.noarch.rpm

# 如果是你 Centos 7,那么可能是如下命令:
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm

# 安装配置仓库(Centos 8)
sudo yum localinstall mysql80-community-release-el8-9.noarch.rpm

# 确认与检查
yum repolist enabled | grep mysql.*-community
mysql-connectors-community MySQL Connectors Community
mysql-tools-community      MySQL Tools Community
mysql80-community          MySQL 8.0 Community Server

2. 打开或关闭需要的子仓库

如上面的输出,可以看到,8.0版本(mysql80-community)子仓库是默认打开的。如果要安装8.0版本,则可以跳过这一步了。但,如果要安装其他版本,例如你希望安装innovation版本,那么可以通过关闭8.0仓库,打开innovation版本子仓库的方式解决。

# 查看有哪些子仓库,以及是否打开
yum repolist all | grep mysql

# 如果需要的话,可以禁用8.0子仓库,打开innovation版子仓库
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql-innovation-community

我们总是可以通过yum repolist命令查看所有仓库的状态:

yum repolist
yum repolist enabled
yum repolist disabled

3. 安装需要的MySQL-Server软件

# 查看仓库和版本
yum list mysql-community-server
mysql-community-server.x86_64      8.2.0-1.el8      mysql-innovation-community

# 安装MySQL 8.2.0
yum install mysql-community-server
...
Complete!

4. 启动数据库

这是一个默认启动。

systemctl start mysqld

总是可以通过如下命令启动/关闭/重启或查看MySQL-Server的状态。

systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
systemctl status mysqld

默认的配置文件

cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

5. 使用root账号登录数据库

MySQL在启动时,会随机生成一个默认的root密码,首次登录需要获取该密码,并在登录后,立刻修改密码。

获取密码:
# 从日志文件中获取密码
grep 'temporary password' /var/log/mysqld.log
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: p!5h)W9DikW/
登录并修改密码:
# 登录
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.2.0

Copyright (c) 2000, 2023, 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.

# 修改默认的root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

6. 一种不安全、但是偷懒的做法

这是一种非常不安全的做法,但是很方便:可以在配置文件(my.cnf)中新增skip-grant-tables=ON参考)来关闭MySQL的用户认证与鉴权体系,谨慎使用

这时候,就可以没有任何密码,不用关注任何权限去登录与使用数据库。不过,为了安全考虑,该参数打开后,数据库也会禁用所有远程的连接,仅允许本地的访问。

EOF

参考:

In:

Leave a Reply

Your email address will not be published. Required fields are marked *