Ubuntu安裝MySQL資料庫

小陳運維發表於2023-12-08

Ubuntu安裝MySQL資料庫

介紹

MySQL 的定義
MySQL 是一種開源關係型資料庫管理系統。與其他關係型資料庫一樣,MySQL 將資料儲存在由行和列組成的表中。使用者可以使用結構化查詢語言(通常稱為 SQL)定義、操作、控制和查詢資料。由於 MySQL 是開源的,因此它的大量功能是在超過 25 年與使用者密切合作的過程中開發出來的。

MySQL 軟體是開源的
MySQL 是開源的,這意味著按照 GNU 通用公共許可條款,該工具可以免費使用。這也意味著,任何人都可以根據自己的使用需求自由修改軟體的原始碼。這使得 MySQL 分支為其他資料庫變體(例如 MariaDB 和 Percona Server for MySQL)。MySQL 也可以透過其他許可用於商業用途。

關係型資料庫
MySQL 所屬的資料庫類別稱為關係型資料庫管理系統 (RDBMS)。關係型資料庫是資訊的集合,它以預定義的關係組織資料,資料儲存在一個或多個由列和行構成的表(或稱“關係”)中,使用者可以輕鬆檢視和理解不同資料結構之間的關係。關係是不同表之間的邏輯連線,根據這些表之間的互動建立。

下載

下載地址https://dev.mysql.com/downloads/在此頁面中,需要選擇你要安裝的版本型別,我這裡是Ubuntu系統所以選擇 MySQL APT Repository,若你使用CentOS那麼就使用MySQL Yum Repository

#下載地址
# https://dev.mysql.com/downloads/

# 選擇你要安裝的版本型別,我這裡是Ubuntu系統所以選擇 MySQL APT Repository,若你使用CentOS那麼就使用MySQL Yum Repository

apt install https://dev.mysql.com/get/mysql-apt-config_0.8.28-1_all.deb

# 安裝MySQL-Server
apt install mysql-community-server

# 檢視服務是否正常
root@cby:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-12-06 15:35:30 CST; 22min ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 9786 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 3943)
     Memory: 369.3M
        CPU: 3.989s
     CGroup: /system.slice/mysql.service
             └─9786 /usr/sbin/mysqld

Dec 06 15:35:29 cby systemd[1]: Starting MySQL Community Server...
Dec 06 15:35:30 cby systemd[1]: Started MySQL Community Server.
root@cby:~# 

開啟外部訪問

# 登入資料庫
root@cby:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.35 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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>


# 檢視預設庫
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

# 選擇使用mysql庫
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 
mysql> 

# 查詢使用者表
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | $A$005$yWgZ hKW4{ege
                                                     W/5pMsmD7O.Tq.KL8z9ARsM1TcL74ysSUXrqH0pWKEj5 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> 

# 修改root的授權
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> 
mysql> 
mysql> Grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> 

# 重新整理許可權
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> 
mysql>
mysql> ^DBye
root@cby:~# 
root@cby:~#

測試

# 使用其他主機進行登入資料庫
root@cby:~# mysql -u root -p -h x.oiox.cn
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.35 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> 
mysql> 
mysql> ^DBye
root@cby:~# 
root@cby:~# 

關於

https://www.oiox.cn/

https://www.oiox.cn/index.php/start-page.html

CSDN、GitHub、51CTO、知乎、開源中國、思否、部落格園、掘金、簡書、華為雲、阿里雲、騰訊雲、嗶哩嗶哩、今日頭條、新浪微博、個人部落格

全網可搜《小陳運維》

文章主要釋出於微信公眾號

相關文章