美文网首页
CentOS 7.x 安装 MySQL 8.x

CentOS 7.x 安装 MySQL 8.x

作者: 又语 | 来源:发表于2019-11-20 17:17 被阅读0次

本文介绍在 CentOS 7.x 操作系统上安装 MySQL 8.x 的方法与过程。


版本说明

  • CentOS Linux release 7.6
  • MySQL 8.0.18

安装步骤

  1. 执行命令 rpm -qa|grep mysql 查询已安装 MySQL
[root@... ~]# rpm -qa|grep mysql
qt-mysql-4.8.7-2.el7.x86_64
akonadi-mysql-1.9.2-4.el7.x86_64
  1. 执行命令 rpm -e 卸载(注意卸载顺序)。
[root@... ~]# rpm -e akonadi-mysql-1.9.2-4.el7.x86_64
[root@... ~]# rpm -e qt-mysql-4.8.7-2.el7.x86_64

如果卸载失败则使用命令 rpm -e --nodeps 强制卸载。

  1. 执行命令 rpm -qa|grep mariadb 查询系统自带的 mariadb
[root@... ~]# rpm -qa|grep mariadb
mariadb-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-server-5.5.60-1.el7_5.x86_64
  1. 执行命令 rpm -e 卸载(注意卸载顺序)。
[root@... ~]# rpm -e mariadb-server-5.5.60-1.el7_5.x86_64
warning: file /var/log/mariadb/mariadb.log: remove failed: No such file or directory
[root@... ~]# rpm -e mariadb-5.5.60-1.el7_5.x86_64
[root@... ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

如果卸载失败则使用命令 rpm -e --nodeps 强制卸载。

  1. 下载 MySQL,选择 Red Hat Enterprise Linux / Oracle Linux -> Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit) -> RPM Bundle

  2. 将下载文件 mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar 拷贝到 CentOS 服务器特定目录下,如 /opt

  3. 执行解压命令 tar -xvf

[root@... mysql]# tar -xvf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-8.0.18-1.el7.x86_64.rpm
mysql-community-devel-8.0.18-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm
mysql-community-common-8.0.18-1.el7.x86_64.rpm
mysql-community-test-8.0.18-1.el7.x86_64.rpm
mysql-community-server-8.0.18-1.el7.x86_64.rpm
mysql-community-client-8.0.18-1.el7.x86_64.rpm
  1. 依次安装 commonlibsclientserver
[root@... mysql]# rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.18-1.e################################# [100%]
[root@... mysql]# rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.18-1.el7################################# [100%]
[root@... mysql]# rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.18-1.e################################# [100%]
[root@... mysql]# rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.18-1.e################################# [100%]
  1. 执行命令 rpm -qa | grep mysql 检查安装结果。
[root@... mysql]# rpm -qa | grep mysql
mysql-community-client-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-server-8.0.18-1.el7.x86_64
  1. 执行初始化命令 mysqld --initialize

  2. 执行命令 cat /var/log/mysqld.log | grep password 查看初始化密码。

[root@... mysql]# cat /var/log/mysqld.log | grep password
2019-11-20T10:32:40.387358Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ntwpg2Jift+R
  1. 执行启动命令 systemctl start mysqld 报错。
[root@... log]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
  1. 执行命令 vim /var/log/mysqld.log 查看错误日志。
2019-11-20T10:46:34.927570Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.18) starting as process 49601
2019-11-20T10:46:34.937662Z 1 [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2019-11-20T10:46:34.937746Z 1 [ERROR] [MY-012278] [InnoDB] The innodb_system data file 'ibdata1' must be writable
2019-11-20T10:46:34.937806Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2019-11-20T10:46:34.937971Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-11-20T10:46:34.938041Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-11-20T10:46:34.938799Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.18)  MySQL Community Server - GPL.

原因分析:安装时使用 root 用户身份,但 MySQL 要求执行身份是 mysql,因权限问题导致数据文件不可写。
解决方法:执行 chown -R 命令将 /var/lib/mysql 目录权限赋予 mysql

[root@... log]# chown -R mysql /var/lib/mysql
  1. 再次执行启动命令 systemctl start mysqld

  2. 执行命令 service mysqld status 查看 MySQL 状态。

[root@... log]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-11-20 18:59:57 CST; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 51977 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 52007 (mysqld)
   Status: "Server is operational"
    Tasks: 39
   CGroup: /system.slice/mysqld.service
           └─52007 /usr/sbin/mysqld

Nov 20 18:59:55 ctup000105163 systemd[1]: Starting MySQL Server...
Nov 20 18:59:57 ctup000105163 systemd[1]: Started MySQL Server.
  1. 执行登录命令 mysql -uroot -pntwpg2Jift+R
[root@... log]# mysql -uroot -pntwpg2Jift+R
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>
  1. 执行 SQL:ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 修改密码。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '******';
Query OK, 0 rows affected (0.01 sec)
  1. 配置 root 用户远程访问。
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> UPDATE user SET host='%' WHERE user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

相关文章

网友评论

      本文标题:CentOS 7.x 安装 MySQL 8.x

      本文链接:https://www.haomeiwen.com/subject/zuaoictx.html