欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux搭建單機MySQL8.0.26版本的操作方法

 更新時間:2025年05月05日 08:26:41   作者:huangSir-devops  
這篇文章主要介紹了Linux搭建單機MySQL8.0.26版本的操作方法,本文通過圖文并茂的形式給大家講解的非常詳細(xì),感興趣的朋友一起看看吧

概述

本文主要是寫Ubuntu22.04搭建MySQL8.0.26版本

環(huán)境信息

IP系統(tǒng)規(guī)格
10.0.0.10Ubuntu22.042c4g

數(shù)據(jù)庫服務(wù)安裝步驟

下載前置依賴

# 下載libtinfo5、libnuma1依賴
[root@lb ~]# apt update -y && apt install -y libtinfo5 libnuma1

服務(wù)下載

方式一:進(jìn)入官網(wǎng)下載,并上傳到宿主機中,適合離線環(huán)境

官網(wǎng)下載地址: https://downloads.mysql.com/archives/community/

方式二:直接在宿主機中使用wget進(jìn)行下載,適合宿主機聯(lián)網(wǎng)環(huán)境

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

服務(wù)解壓并創(chuàng)建軟鏈接

# 服務(wù)解壓至家目錄
[root@lb ~]# tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
# 創(chuàng)建軟鏈接
[root@lb ~]# ln -s mysql-8.0.26-linux-glibc2.12-x86_64 mysql
# 查看
[root@lb ~]# ll | grep mysql
lrwxrwxrwx  1 root root        35 May  1 15:43 mysql -> mysql-8.0.26-linux-glibc2.12-x86_64/
drwxr-xr-x  9 root root      4096 May  1 15:43 mysql-8.0.26-linux-glibc2.12-x86_64/
-rw-r--r--  1 root root 914806904 Jul  2  2021 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

配置環(huán)境變量

# /root/mysql/bin根據(jù)你安裝的實際地址來進(jìn)行替換
[root@lb ~]# echo 'export PATH=/root/mysql/bin:$PATH' >> /etc/profile
[root@lb ~]# source /etc/profile

檢查環(huán)境變量是否配置正確

[root@lb ~]# mysql -V
mysql  Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)

創(chuàng)建MySQL的虛擬用戶

[root@lb ~]# useradd -s /sbin/nologin -M mysql

創(chuàng)建數(shù)據(jù)存儲目錄,并修改目錄的擁有者

[root@lb ~]# mkdir -p /data/mysql/data
[root@lb ~]# chown -R mysql.mysql /data/mysql/data

初始化數(shù)據(jù)庫

# 初始化數(shù)據(jù)庫,沒有報錯即代表成功
[root@lb ~]# mysqld --initialize-insecure  --user=mysql  --datadir=/data/mysql/data  --basedir=/root/mysql
2025-05-01T07:59:04.638615Z 0 [System] [MY-013169] [Server] /root/mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 132486
2025-05-01T07:59:04.656989Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-05-01T07:59:05.254538Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-05-01T07:59:05.950015Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2025-05-01T07:59:05.950635Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2025-05-01T07:59:06.009584Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

參數(shù)解釋:

  • --initialize-insecure:不安全的初始化,表示數(shù)據(jù)庫啟動后沒有密碼信息,
  • --initialize:安全初始化,表示數(shù)據(jù)庫啟動后,會有默認(rèn)的密碼信息
  • --user:指定用戶
  • --datadir:指定數(shù)據(jù)存儲目錄
  • --basedir:指定MySQL安裝的目錄

數(shù)據(jù)庫初始化成功之后數(shù)據(jù)目錄會有以下文件

[root@lb ~]# ll /data/mysql/data/
total 177608
-rw-r----- 1 mysql mysql   196608 May  1 15:59 '#ib_16384_0.dblwr'
-rw-r----- 1 mysql mysql  8585216 May  1 15:59 '#ib_16384_1.dblwr'
drwxr-x--- 2 mysql mysql     4096 May  1 15:59 '#innodb_temp'/
drwxr-xr-x 6 mysql mysql     4096 May  1 15:59  ./
drwxr-xr-x 3 root  root      4096 May  1 15:56  ../
-rw-r----- 1 mysql mysql       56 May  1 15:59  auto.cnf
-rw------- 1 mysql mysql     1676 May  1 15:59  ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 May  1 15:59  ca.pem
-rw-r--r-- 1 mysql mysql     1112 May  1 15:59  client-cert.pem
-rw------- 1 mysql mysql     1680 May  1 15:59  client-key.pem
-rw-r----- 1 mysql mysql     5995 May  1 15:59  ib_buffer_pool
-rw-r----- 1 mysql mysql 50331648 May  1 15:59  ib_logfile0
-rw-r----- 1 mysql mysql 50331648 May  1 15:59  ib_logfile1
-rw-r----- 1 mysql mysql 12582912 May  1 15:59  ibdata1
drwxr-x--- 2 mysql mysql     4096 May  1 15:59  mysql/
-rw-r----- 1 mysql mysql 26214400 May  1 15:59  mysql.ibd
drwxr-x--- 2 mysql mysql     4096 May  1 15:59  performance_schema/
-rw------- 1 mysql mysql     1676 May  1 15:59  private_key.pem
-rw-r--r-- 1 mysql mysql      452 May  1 15:59  public_key.pem
-rw-r--r-- 1 mysql mysql     1112 May  1 15:59  server-cert.pem
-rw------- 1 mysql mysql     1680 May  1 15:59  server-key.pem
drwxr-x--- 2 mysql mysql     4096 May  1 15:59  sys/
-rw-r----- 1 mysql mysql 16777216 May  1 15:59  undo_001
-rw-r----- 1 mysql mysql 16777216 May  1 15:59  undo_002

編寫MySQL配置文件

[root@lb ~]# cat /etc/my.cnf
[mysqld]
# 數(shù)據(jù)庫文件的存儲路徑
datadir=/data/mysql/data
# 服務(wù)器監(jiān)聽的端口號
port=3306
# 字符集設(shè)置
character-set-server=utf8mb4
# 排序規(guī)則
collation-server=utf8mb4_general_ci
# 允許的最大連接數(shù)
max_connections=1000
# MySQL服務(wù)器的緩存大小,用于緩存數(shù)據(jù)和索引
innodb_buffer_pool_size=1G
# 日志文件的路徑
log_error=/var/log/mysql/error.log
# 慢查詢?nèi)罩疚募穆窂?
slow_query_log_file=/var/log/mysql/slow-query.log
# 開啟慢查詢?nèi)罩荆?表示開啟,0表示關(guān)閉
slow_query_log=1
# 設(shè)定慢查詢的時間閾值,單位為秒,超過此時間的查詢將被記錄到慢查詢?nèi)罩局?
long_query_time=3
# 設(shè)置用戶
user=mysql
# 設(shè)置socket連信息
socket=/tmp/mysql.sock
[client]
# 客戶端默認(rèn)字符集
default-character-set=utf8mb4
[mysql]
# MySQL命令行工具的默認(rèn)字符集
default-character-set=utf8mb4
 

創(chuàng)建日志目錄

[root@lb ~]# mkdir -p /var/log/mysql/
[root@lb ~]# chown -R mysql.mysql /var/log/mysql/

修改MySQL安裝目錄中的啟動文件

拷貝啟動文件至/etc/init.d目錄下

[root@lb ~]# cp /root/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@lb ~]# chmod +x /etc/init.d/mysqld

修改啟動文件的內(nèi)容
vim /etc/init.d/mysqld

啟動MySQL服務(wù)

# 沒報錯即代表啟動成功
[root@lb ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl): mysqld.service.
# 檢查端口號
[root@lb ~]# ss -lntup | grep 3306
tcp   LISTEN 0      70                 *:33060            *:*    users:(("mysqld",pid=144896,fd=21))
tcp   LISTEN 0      1000               *:3306             *:*    users:(("mysqld",pid=144896,fd=24))

修改root用戶密碼

[root@lb ~]# mysqladmin -u root password "huangsir"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

登錄MySQL服務(wù)

[root@lb ~]# mysql -uroot -phuangsir
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 10
Server version: 8.0.26 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>

遠(yuǎn)程連接MySQL

MySQL默認(rèn)的root用戶是無法遠(yuǎn)程登錄的,所以我們需要創(chuàng)建一個用戶用于遠(yuǎn)程登錄

# 創(chuàng)建用戶,10.0.0.0/24代表網(wǎng)段,只有在這個網(wǎng)段之內(nèi)的IP才能連接數(shù)據(jù)庫,密碼設(shè)置為huangsir
mysql> CREATE USER 'root'@'10.0.0.0/24' IDENTIFIED BY 'huangsir';
Query OK, 0 rows affected (0.01 sec)
# 授權(quán),*.*代表所有的庫和表
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.0.0.0/24' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
# 刷新權(quán)限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

使用navicat連接數(shù)據(jù)庫測試

到此這篇關(guān)于Linux系統(tǒng)搭建單機MySQL8.0.26版本的文章就介紹到這了,更多相關(guān)linux mysql8.0搭建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論