IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> CentOS7.4上MySQL8.0.21从安装到卸载 -> 正文阅读

[大数据]CentOS7.4上MySQL8.0.21从安装到卸载

一、准备安装包和卸载旧版

上传mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar文件到服务器

卸载旧版mysql和mariadb,避免冲突

rpm -qa|grep mariadb

rpm -qa|grep mysql

通过rpm -e --nodeps命令卸载

[root@testmachine install]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@testmachine install]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

二、解压tar包并通过rpm命令进行安装

解压 tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar

[root@testmachine install]# tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
mysql-community-common-8.0.21-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-8.0.21-1.el7.x86_64.rpm
mysql-community-devel-8.0.21-1.el7.x86_64.rpm
mysql-community-server-8.0.21-1.el7.x86_64.rpm
mysql-community-client-8.0.21-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.21-1.el7.x86_64.rpm
mysql-community-test-8.0.21-1.el7.x86_64.rpm

使用命令rpm -ivh进行安装操作? 按照common–>lib–>client–>server这个顺序安装

rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm

过程参考下图

[root@testmachine install]# rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.0.21-1.e################################# [100%]
[root@testmachine install]# rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.21-1.el7################################# [100%]
[root@testmachine install]# rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.21-1.e################################# [100%]
[root@testmachine install]# rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.21-1.e################################# [100%]
[root@testmachine install]#

三、配置数据库

执行命令初始化

mysqld --initialize --console --user=mysql

启动数据库?

systemctl start mysqld.service

查看数据库状态?systemctl status mysqld.service

[root@testmachine bin]# systemctl status mysqld
?mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-23 17:31:19 CST; 54s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3528 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3602 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           忖3602 /usr/sbin/mysqld

Sep 23 17:31:12 testmachine systemd[1]: Starting MySQL Server...
Sep 23 17:31:19 testmachine systemd[1]: Started MySQL Server.

在日志中获取数据库临时密码 (不知道路径的可以查看配置文件/etc/my.cnf)

[root@testmachine bin]# cat /var/log/mysqld.log
2021-09-23T09:29:26.350384Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 3468
2021-09-23T09:29:26.361836Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-09-23T09:29:27.166842Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-09-23T09:29:28.709599Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: DyeBakQ9<GdE
2021-09-23T09:31:12.547649Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.21) initializing of server in progress as process 3555
2021-09-23T09:31:12.559747Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-09-23T09:31:13.150743Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-09-23T09:31:15.170523Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qYyXQ&fCX9vk
2021-09-23T09:31:19.029693Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.21) starting as process 3602
2021-09-23T09:31:19.055801Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-09-23T09:31:19.469806Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-09-23T09:31:19.675098Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2021-09-23T09:31:19.950673Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-09-23T09:31:19.950985Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-09-23T09:31:19.989893Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.21'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.

登录进数据库

mysql -u root -p


输入临时密码 成功进入

修改密码

ALTER USER root@localhost identified by '密码';


授权远程登录

USE MYSQL;

update user set host = '%' where user = 'root';

刷新权限

FLUSH PRIVILEGES;

CTRL+D退出

[root@testmachine bin]# 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.21

Copyright (c) 2000, 2020, 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> use mysql;
Database changed

mysql> ALTER USER root@localhost identified by 'GBs01Y4$P';
Query OK, 0 rows affected (0.01 sec)

mysql> update user set host = '%' where user = 'root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

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

至此数据库安装完成

四、设置开机启动和关闭防火墙

chkconfig mysqld on

添加软连接

ln -s /usr/local/mysql/bin/mysql /usr/bin

永久关闭SELINUX

vi /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled
设置后需要重启才能生效?

[root@testmachine ~]# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

查看selinux状态 sestatus

[root@testmachine ~]# sestatus
SELinux status:                 disabled

五、卸载数据库

1.查看系统中是否以rpm包安装的mysql

输入命令?rpm -qa|grep mysql

[root@testmachine ~]# rpm -qa | grep mysql
mysql-community-libs-8.0.21-1.el7.x86_64
mysql-community-client-8.0.21-1.el7.x86_64
mysql-community-server-8.0.21-1.el7.x86_64
mysql-community-common-8.0.21-1.el7.x86_64
[root@testmachine ~]# 

2.通过rpm -e 卸载软件包

rpm -e --nodeps mysql-community-common-8.0.21-1.el7.x86_64.rpm
rpm -e --nodeps mysql-community-libs-8.0.21-1.el7.x86_64.rpm
rpm -e --nodeps mysql-community-client-8.0.21-1.el7.x86_64.rpm
rpm -e --nodeps mysql-community-server-8.0.21-1.el7.x86_64.rpm 
[root@testmachine ~]# rpm -e --nodeps mysql-community-common-8.0.21-1.el7.x86_64
[root@testmachine ~]# rpm -e --nodeps mysql-community-libs-8.0.21-1.el7.x86_64
[root@testmachine ~]# rpm -e --nodeps mysql-community-client-8.0.21-1.el7.x86_64
[root@testmachine ~]# rpm -e --nodeps mysql-community-server-8.0.21-1.el7.x86_64 
warning: /etc/my.cnf saved as /etc/my.cnf.rpmsave

卸载完了可以再次运行rpm -qa|grep mysql检查

3.mysql程序命令进行删除相关目录

[root@testmachine ~]#  whereis mysql
mysql: /usr/lib64/mysql
[root@testmachine ~]# rm  -rf /usr/lib64/mysql
[root@testmachine ~]# 

卸载完成

六、修改数据库的数据目录datadir

停止mysql,并确保它成功停止了

[root@testmachine ~]# systemctl stop mysqld.service
[root@CNGSCAPL-VPD403 ~]# systemctl status mysqld.service
?mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2021-09-23 23:17:28 CST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5100 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5076 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5100 (code=exited, status=0/SUCCESS)
   Status: "Server shutdown complete"

Sep 23 22:46:14 testmachine systemd[1]: Starting MySQL Server...
Sep 23 22:46:17 testmachine  systemd[1]: Started MySQL Server.
Sep 23 23:17:25 testmachine  systemd[1]: Stopping MySQL Server...
Sep 23 23:17:28 testmachine  systemd[1]: Stopped MySQL Server.

在新位置创建目录并将所有权更改到mysql下

[root@testmachine ~]# mkdir -p /data/mysql
[root@testmachine ~]# chown -R mysql:mysql /data/mysql
[root@testmachine ~]# rsync -av /var/lib/mysql /data/mysql/

将文件移动到新的数据目录中: rsync -av /var/lib/mysql /data/mysql/

[root@testmachine ~]# rsync -av /var/lib/mysql /data/mysql/
sending incremental file list
mysql/
mysql/#ib_16384_0.dblwr
mysql/#ib_16384_1.dblwr
mysql/auto.cnf
mysql/binlog.000001
mysql/binlog.000002
mysql/binlog.000003
mysql/binlog.000004
mysql/binlog.index
mysql/ca-key.pem
mysql/ca.pem
mysql/client-cert.pem
mysql/client-key.pem
mysql/ib_buffer_pool
mysql/ib_logfile0
mysql/ib_logfile1
mysql/ibdata1
mysql/mysql.ibd
mysql/private_key.pem
mysql/public_key.pem
mysql/server-cert.pem
mysql/server-key.pem
mysql/undo_001
mysql/undo_002
mysql/#innodb_temp/
mysql/mysql/
mysql/mysql/general_log.CSM
mysql/mysql/general_log.CSV
mysql/mysql/general_log_207.sdi
mysql/mysql/slow_log.CSM
mysql/mysql/slow_log.CSV
mysql/mysql/slow_log_208.sdi
mysql/performance_schema/
mysql/performance_schema/accounts_142.sdi
mysql/performance_schema/binary_log_trans_184.sdi
mysql/performance_schema/cond_instances_81.sdi
mysql/performance_schema/data_lock_waits_158.sdi
mysql/performance_schema/data_locks_157.sdi
mysql/performance_schema/events_errors_su_136.sdi
mysql/performance_schema/events_errors_su_137.sdi
mysql/performance_schema/events_errors_su_138.sdi
mysql/performance_schema/events_errors_su_139.sdi
mysql/performance_schema/events_errors_su_140.sdi
mysql/performance_schema/events_stages_cu_108.sdi
mysql/performance_schema/events_stages_hi_109.sdi
mysql/performance_schema/events_stages_hi_110.sdi
mysql/performance_schema/events_stages_su_111.sdi
mysql/performance_schema/events_stages_su_112.sdi
mysql/performance_schema/events_stages_su_113.sdi
mysql/performance_schema/events_stages_su_114.sdi
mysql/performance_schema/events_stages_su_115.sdi
mysql/performance_schema/events_statement_116.sdi
mysql/performance_schema/events_statement_117.sdi
mysql/performance_schema/events_statement_118.sdi
mysql/performance_schema/events_statement_119.sdi
mysql/performance_schema/events_statement_120.sdi
mysql/performance_schema/events_statement_121.sdi
mysql/performance_schema/events_statement_122.sdi
mysql/performance_schema/events_statement_123.sdi
mysql/performance_schema/events_statement_124.sdi
mysql/performance_schema/events_statement_125.sdi
mysql/performance_schema/events_statement_126.sdi
mysql/performance_schema/events_statement_127.sdi
mysql/performance_schema/events_transacti_128.sdi
mysql/performance_schema/events_transacti_129.sdi
mysql/performance_schema/events_transacti_130.sdi
mysql/performance_schema/events_transacti_131.sdi
mysql/performance_schema/events_transacti_132.sdi
mysql/performance_schema/events_transacti_133.sdi
mysql/performance_schema/events_transacti_134.sdi
mysql/performance_schema/events_transacti_135.sdi
mysql/performance_schema/events_waits_cur_82.sdi
mysql/performance_schema/events_waits_his_83.sdi
mysql/performance_schema/events_waits_his_84.sdi
mysql/performance_schema/events_waits_sum_85.sdi
mysql/performance_schema/events_waits_sum_86.sdi
mysql/performance_schema/events_waits_sum_87.sdi
mysql/performance_schema/events_waits_sum_88.sdi
mysql/performance_schema/events_waits_sum_89.sdi
mysql/performance_schema/events_waits_sum_90.sdi
mysql/performance_schema/file_instances_91.sdi
mysql/performance_schema/file_summary_by__92.sdi
mysql/performance_schema/file_summary_by__93.sdi
mysql/performance_schema/global_status_176.sdi
mysql/performance_schema/global_variables_179.sdi
mysql/performance_schema/host_cache_94.sdi
mysql/performance_schema/hosts_143.sdi
mysql/performance_schema/keyring_keys_149.sdi
mysql/performance_schema/log_status_169.sdi
mysql/performance_schema/memory_summary_b_151.sdi
mysql/performance_schema/memory_summary_b_152.sdi
mysql/performance_schema/memory_summary_b_153.sdi
mysql/performance_schema/memory_summary_b_154.sdi
mysql/performance_schema/memory_summary_g_150.sdi
mysql/performance_schema/metadata_locks_156.sdi
mysql/performance_schema/mutex_instances_95.sdi
mysql/performance_schema/objects_summary__96.sdi
mysql/performance_schema/performance_time_97.sdi
mysql/performance_schema/persisted_variab_182.sdi
mysql/performance_schema/prepared_stateme_170.sdi
mysql/performance_schema/replication_appl_162.sdi
mysql/performance_schema/replication_appl_163.sdi
mysql/performance_schema/replication_appl_164.sdi
mysql/performance_schema/replication_appl_165.sdi
mysql/performance_schema/replication_appl_167.sdi
mysql/performance_schema/replication_appl_168.sdi
mysql/performance_schema/replication_conn_159.sdi
mysql/performance_schema/replication_conn_161.sdi
mysql/performance_schema/replication_grou_160.sdi
mysql/performance_schema/replication_grou_166.sdi
mysql/performance_schema/rwlock_instances_98.sdi
mysql/performance_schema/session_account__148.sdi
mysql/performance_schema/session_connect__147.sdi
mysql/performance_schema/session_status_177.sdi
mysql/performance_schema/session_variable_180.sdi
mysql/performance_schema/setup_actors_99.sdi
mysql/performance_schema/setup_consumers_100.sdi
mysql/performance_schema/setup_instrument_101.sdi
mysql/performance_schema/setup_objects_102.sdi
mysql/performance_schema/setup_threads_103.sdi
mysql/performance_schema/socket_instances_144.sdi
mysql/performance_schema/socket_summary_b_145.sdi
mysql/performance_schema/socket_summary_b_146.sdi
mysql/performance_schema/status_by_accoun_172.sdi
mysql/performance_schema/status_by_host_173.sdi
mysql/performance_schema/status_by_thread_174.sdi
mysql/performance_schema/status_by_user_175.sdi
mysql/performance_schema/table_handles_155.sdi
mysql/performance_schema/table_io_waits_s_104.sdi
mysql/performance_schema/table_io_waits_s_105.sdi
mysql/performance_schema/table_lock_waits_106.sdi
mysql/performance_schema/threads_107.sdi
mysql/performance_schema/tls_channel_stat_185.sdi
mysql/performance_schema/user_defined_fun_183.sdi
mysql/performance_schema/user_variables_b_171.sdi
mysql/performance_schema/users_141.sdi
mysql/performance_schema/variables_by_thr_178.sdi
mysql/performance_schema/variables_info_181.sdi
mysql/sys/
mysql/sys/sys_config.ibd

sent 169,753,974 bytes  received 2,613 bytes  11,707,350.83 bytes/sec
total size is 169,703,438  speedup is 1.00

修改配置文件 vi /etc/my.cnf
?

[mysqld]

#datadir=/var/lib/mysql
datadir=/data/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/data/mysql/mysql.sock

启动MySQL服务器并确认数据目录已更改:

systemctl start mysqld.service

show variables like '%datadir%';

如果出现报错

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
?

删掉新的数据目录重新创建,可以删除log底下的所有内容,然后重新再执行初始化mysql就可以了

mysqld? --initialize???--datadir=/data/mysql??--user=mysql

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-09-24 10:37:42  更:2021-09-24 10:38:27 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 22:52:33-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码