【推荐 - rpm安装】MySQL - 安装
准备
- 查看Linux系统的glibc运行使用的C语言库版本信息
[root@lab10 ~]# getconf GNU_LIBC_VERSION
glibc 2.17
[root@lab10 ~]# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
- 查看操作系统的版本信息
[root@lab10 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
- 查看操作系统的网卡地址
[root@lab10 ~]# ip address show ens32
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ec:f2:1b brd ff:ff:ff:ff:ff:ff
inet 10.1.1.10/24 brd 10.1.1.255 scope global ens32
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feec:f21b/64 scope link
valid_lft forever preferred_lft forever
- 查看系统本地域名解析信息
[root@lab10 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 查看防火墙服务是否关闭
[root@lab10 ~]# getenforce
Permissive
- 清除系统自带的mariadb数据库服务相关的程序包
[root@lab10 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@lab10 ~]# yum remove -y mariadb-libs
- 安装数据库服务程序所需的依赖软件包
yum install -y libaio-devel
- 需要修改链接库信息(只有
centos 8
系统才需要进行操作修改)
[root@xiaoQ-01 ~]# ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
或者
[root@xiaoQ-01 ~]# yum install ncurses-compat-libs
下载 MySQL
Product Version:
8.2.0
Operating System:Red Hat Enterprise Linux / Oracle Linux
OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
选择RPM Bundle
下载
下载链接如下:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar
文件全称:mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar
文件md5:7c2483e3d1eaa245746f4769bf4f54c5
创建MySQL的源码目录
mkdir -p /opt/mysql
创建MySQL的版本源码目录
mkdir -p /opt/mysql/mysql-8.2.0
上传 MySQL
使用工具上传 MySQL
或者
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar
进入MySQL的源码目录
cd /opt/mysql
解压 MySQL 至指定目录
tar -xvf mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql/mysql-8.2.0
移动目录到/usr/local/mysql
mv mysql-8.2.0 /usr/local/mysql
创建数据库服务管理用户信息
useradd -r -s /sbin/nologin mysql
创建一个数据库专用账号mysql(其所属组也为mysql)
进入安装目录
cd /usr/local/mysql
查看安装rpm
[root@lab10 mysql]# ll
total 1029332
-rw-r--r--. 1 7155 31415 16860000 Oct 13 2023 mysql-community-client-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3617000 Oct 13 2023 mysql-community-client-plugins-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 687048 Oct 13 2023 mysql-community-common-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 549736120 Oct 13 2023 mysql-community-debuginfo-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1963108 Oct 13 2023 mysql-community-devel-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 4217572 Oct 13 2023 mysql-community-embedded-compat-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2344832 Oct 13 2023 mysql-community-icu-data-files-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1583436 Oct 13 2023 mysql-community-libs-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 685776 Oct 13 2023 mysql-community-libs-compat-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 67735456 Oct 13 2023 mysql-community-server-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 26028560 Oct 13 2023 mysql-community-server-debug-8.2.0-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 378554428 Oct 13 2023 mysql-community-test-8.2.0-1.el7.x86_64.rpm
安装(各小版本依赖信息可能不一致,根据提示顺序安装依赖即可)
rpm -ivh mysql-community-common-8.2.0-1.el7.x86_64.rpm \
mysql-community-client-plugins-8.2.0-1.el7.x86_64.rpm \
mysql-community-libs-8.2.0-1.el7.x86_64.rpm \
mysql-community-client-8.2.0-1.el7.x86_64.rpm \
mysql-community-icu-data-files-8.2.0-1.el7.x86_64.rpm \
mysql-community-server-8.2.0-1.el7.x86_64.rpm
可以获取数据库服务版本信息表示环境变量配置生效
[root@lab10 mysql]# mysql -V
mysql Ver 8.2.0 for Linux on x86_64 (MySQL Community Server - GPL)
设置编码格式与端口信息
vim /etc/my.cnf
修改内容如下
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set=utf8mb4
[client]
default-character-set=utf8mb4
启动mysql
systemctl start mysqld.service
查看是否启动
[root@lab10 mysql]# netstat -ntlp | grep mysql
tcp6 0 0 :::33060 :::* LISTEN 58001/mysqld
tcp6 0 0 :::3306 :::* LISTEN 58001/mysqld
获取root默认密码
grep "password" /var/log/mysqld.log
内容如下:
2023-09-12T07:56:02.593722Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: kK%N&gY4ro5i
登录MySQL
mysql -uroot -p'kK%N&gY4ro5i'
修改root密码,此后root的密码位Flzx3qc@
ALTER user user() identified by 'Flzx3qc@';
flush privileges;
开启root远程登录
use mysql;
select host,user,plugin from user;
- 如果是
plugin == caching_sha2_password
ALTER USER 'root'@'localhost' IDENTIFIED WITH sha256_password BY 'Flzx3qc@';
update user set host = '%' where user = 'root';
flush privileges;
- 如果是
plugin == sha256_password
update user set host = '%' where user = 'root';
flush privileges;
查看版本信息与编码格式
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.33 |
+-----------+
1 row in set (0.01 sec)
mysql> show variables like '%character%';
+--------------------------+--------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8mb3 |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)
mysql>
使用Navicat连接MySQL
略
安装参考:https://blog.csdn.net/Controller000/article/details/131121126
好好学习,天天向上。