最新版 MySQL 8.0, 安装细节都在这里了
本文以 mysql-8.0.28 为例,编写安装教程,本文安装环境是 CentOS
1. 首先在官网下载对应版本,此步骤我相信大家都会,就不再赘述
2. 创建 mysql 组和 mysql 用户
groupadd mysqluseradd -r -g mysql -s /bin/false mysql
3. 将下载的 MySQL 压缩文件,拷贝到 /usr/local/, 并解压,创建软连接
cp mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz /usr/localtar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xzln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql
4. 创建 mysql-files 并修改其属主和属组
cd mysqlmkdir mysql-fileschown mysql:mysql mysql-fileschmod 750 mysql-files
5. 创建 MySQL 数据目录,创建 MySQL 全局配置文件
# 创建数据文件shell> mkdir -p /opt/mysql_data/mysql80# 创建配置文件shell> vim my.cnf# 内容如下[mysqld]port = 3306user = mysqldatadir = /opt/mysql_data/mysql80log_error = error.log
6. 初始化数据,并修改 MySQL 安装目录的属组为 root
bin/mysqld --initialize --user=mysql # --initialize-insecure 无密码bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryshell> yum install libaioshell> mysqld --initialize --user=mysql # 再次执行成功shell> bin/mysql_ssl_rsa_setupchown -R root .
7. 启动 MySQL
cp support-files/mysql.server /etc/init.d/mysqldservice mysqld start # 启动 mysql 服务,或者:systemctl start mysqldservice mysqld status # 查看 mysql 状态,或者:systemctl status mysqldservice mysqld stop # 停止 mysql 服务,或者:systemctl stop mysqld
8. 登录 MySQL
export PATH=/usr/local/mysql/bin:$PATH #配置环境变量mysql -uroot -p # 再次登录,在 /opt/mysql_data/mysql80/error.log 查找密码,如下: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 9Server version: 8.0.28 MySQL Community Server - GPLCopyright (c) 2000, 2022, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> set password = '123'; # 修改密码
至此,现在企业常用 MySQL 版本的安装教程都写完了,安装完成之后,如何链接 MySQL 呢,下一篇写 MySQL 的链接,敬请期待......
大家加油!!!
