最新版 MySQL 8.0, 安装细节都在这里了
本文以 mysql-8.0.28 为例,编写安装教程,本文安装环境是 CentOS
1. 首先在官网下载对应版本,此步骤我相信大家都会,就不再赘述
2. 创建 mysql 组和 mysql 用户
groupadd mysql
false mysql useradd -r -g mysql -s /bin/
3. 将下载的 MySQL 压缩文件,拷贝到 /usr/local/, 并解压,创建软连接
local cp mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz /usr/
tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
ln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql
4. 创建 mysql-files 并修改其属主和属组
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
5. 创建 MySQL 数据目录,创建 MySQL 全局配置文件
# 创建数据文件
shell> mkdir -p /opt/mysql_data/mysql80
# 创建配置文件
shell> vim my.cnf
# 内容如下
[mysqld]
port = 3306
user = mysql
datadir = /opt/mysql_data/mysql80
log_error = error.log
6. 初始化数据,并修改 MySQL 安装目录的属组为 root
# --initialize-insecure 无密码 bin/mysqld --initialize --user=mysql
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
shell> yum install libaio
shell> mysqld --initialize --user=mysql # 再次执行成功
shell> bin/mysql_ssl_rsa_setup
chown -R root .
7. 启动 MySQL
cp support-files/mysql.server /etc/init.d/mysqld
# 启动 mysql 服务,或者:systemctl start mysqld service mysqld start
# 查看 mysql 状态,或者:systemctl status mysqld service mysqld status
# 停止 mysql 服务,或者:systemctl stop mysqld service mysqld stop
8. 登录 MySQL
export PATH=/usr/local/mysql/bin:$PATH #配置环境变量
# 再次登录,在 /opt/mysql_data/mysql80/error.log 查找密码,如下: mysql -uroot -p
2022-03-03T03:33:49.812373Z 1 [Note] A temporary password is generated for root@localhost: 4ojuihu(OhBw
9. 修改密码
shell> mysql -uroot -p # 登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 MySQL Community Server - GPL
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> set password = '123'; # 修改密码
至此,现在企业常用 MySQL 版本的安装教程都写完了,安装完成之后,如何链接 MySQL 呢,下一篇写 MySQL 的链接,敬请期待......
大家加油!!!