【推薦 - glibc安裝】MySQL - 安裝

chan_炽烽發表於2024-09-11

準備

  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/*

相關文章