【推荐 - glibc安装】MySQL - 安装

准备

  1. 查看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@mysql ~]# rpm -qa | grep glibc
glibc-common-2.17-317.el7.x86_64
glibc-headers-2.17-317.el7.x86_64
glibc-devel-2.17-317.el7.x86_64
glibc-2.17-317.el7.x86_64
compat-glibc-2.12-4.el7.centos.x86_64
compat-glibc-headers-2.12-4.el7.centos.x86_64
  1. 查看操作系统的版本信息
[root@lab10 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
  1. 查看操作系统的网卡地址
[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
  1. 查看系统本地域名解析信息
[root@lab10 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  1. 查看防火墙服务是否关闭
[root@lab10 ~]# getenforce 
Permissive
  1. 清除系统自带的mariadb数据库服务相关的程序包
[root@lab10 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@lab10 ~]# yum remove -y mariadb-libs
  1. 安装数据库服务程序所需的依赖软件包
yum install -y libaio-devel
  1. 需要修改链接库信息(只有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

访问页面:MySQL Product Archives

Product Version: 8.2.0
Operating System: Linux - Generic
OS Version: Linux - Generic (glibc 2.17) (ARM, 64-bit)
选择Compressed TAR Archive下载

下载链接如下:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.2.0-linux-glibc2.17-x86_64.tar.xz
文件全称:mysql-8.2.0-linux-glibc2.17-x86_64.tar.xz
文件md5:5e37b5f8988d2bc0bfabc39f5b7f9a08

创建MySQL的源码目录

mkdir -p /opt/mysql

上传 MySQL

使用工具上传 MySQL

或者

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.2.0-linux-glibc2.17-x86_64.tar.xz

进入mysql源码目录

cd /opt/mysql

解压

tar -xvf mysql-8.2.0-linux-glibc2.17-x86_64.tar.xz

迁移mysql工作目录

mv mysql-8.2.0-linux-glibc2.17-x86_64 /usr/local/mysql

配置数据库服务程序环境变量

[root@lab10 ~]# tail -1 /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@lab10 ~]# source /etc/profile

可以获取数据库服务版本信息表示环境变量配置生效

[root@lab10 mysql]# mysql -V
mysql  Ver 8.2.0 for Linux on x86_64 (MySQL Community Server - GPL)

创建数据库服务管理用户信息

useradd -r -s /sbin/nologin mysql

创建一个数据库专用账号mysql(其所属组也为mysql)

数据库初始化操作

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql &> /root/mysql_init_password.txt

/usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

上面的操作为设置安全加密连接(SSL),数据传输会采用加密形式,适合敏感数据

MySQL 的 mysql_ssl_rsa_setup 命令已经被弃用,并将在未来的版本中被移除的警告。告警如下

WARNING: mysql_ssl_rsa_setup is deprecated and will be removed in a future version. Use the mysqld server instead.

MySQL 8.0 以后的版本默认会在服务器启动时自动生成 SSL 和 RSA 文件,所以 mysql_ssl_rsa_setup 命令不再需要。如果你的 MySQL 版本是 8.0 或更高,你可以直接忽略这个警告。

复制mysql脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

编辑mysqld

vi /etc/init.d/mysqld

修改内容如下

# 第46行
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

启动mysql

service mysqld start

进入mysql工作目录

cd /usr/local/mysql

创建my.cnf的配置文件

vim my.cnf

修改内容如下

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/master.err
log-bin=/usr/local/mysql/data/binlog		=>	  一定要开启二进制日志
server-id=10
character_set_server=utf8mb4			 	=>    utf8mb4相当于utf8升级版

配置完成后,重启mysqld服务

service mysqld restart
chkconfig --add mysqld
chkconfig mysqld on

查看是否启动

[root@lab10 mysql]# netstat -ntlp | grep mysql
tcp6       0      0 :::33060                :::*                    LISTEN      58001/mysqld        
tcp6       0      0 :::3306                 :::*                    LISTEN      58001/mysqld

获取root默认密码

grep "password" /root/mysql_init_password.txt

内容如下:

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

其他

也可以使用如下,未经过测试

# 数据库服务初始化操作过程
[root@xiaoQ-01 local]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3306/data
2022-10-11T16:33:20.057586Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 33820
2022-10-11T16:33:20.099560Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-11T16:33:20.490688Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-11T16:33:21.202672Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-10-11T16:33:21.203068Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-10-11T16:33:21.292047Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
-- 数据库初始化过程,就是将数据库默认的系统数据信息创建出来,以及根据配置文件激活数据库的特定功能;
​
# 数据库服务初始化经典报错信息
报错情况-01:
[报错信息]:
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[解决方法]:
yum install -y libaio-devel
​
报错情况-02:
[报错信息]:
initialize specified but the data directory has files in it. Aborting.
The designated data directory /data/3306/data/ is unusable. You can remove all files that the server added to it.
[解决方法]:
rm -rf /data/3306/data/*
posted @ 2024-09-11 00:16  chan_炽烽  阅读(19)  评论(0编辑  收藏  举报