安裝MySQL8
MySQL Community Server 社區(qū)版本,開(kāi)源免費(fèi),自由下載,但不提供官方技術(shù)支持,適用于大多數(shù)普通用戶(hù)。
MySQL Enterprise Edition 企業(yè)版本,需付費(fèi),不能在線下載,可以試用30天。提供了更多的功能和更完備的技術(shù)支持,更適合于對(duì)數(shù)據(jù)庫(kù)的功能和可靠性要求較高的企業(yè)客戶(hù)。
MySQL Cluster 集群版,開(kāi)源免費(fèi)。用于架設(shè)集群服務(wù)器,可將幾個(gè)MySQL Server封裝成一個(gè)Server。需要在社區(qū)版或企業(yè)版的基礎(chǔ)上使用。
MySQL Cluster CGE 高級(jí)集群版,需付費(fèi)。
安裝 mysql yum源
[root@web ~]# wget https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm
[root@web ~]# yum install ./mysql84-community-release-el9-1.noarch.rpm
[root@web ~]#
安裝成功后,查看MySQL版本:
[root@web ~]# yum repolist all | grep mysql
mysql-8.4-lts-community MySQL 8.4 LTS Community Server 啟用
mysql-8.4-lts-community-debuginfo MySQL 8.4 LTS Community Server 禁用
mysql-8.4-lts-community-source MySQL 8.4 LTS Community Server 禁用
mysql-cluster-8.0-community MySQL Cluster 8.0 Community 禁用
mysql-cluster-8.0-community-debuginfo MySQL Cluster 8.0 Community - 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - 禁用
mysql-cluster-8.4-lts-community MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-8.4-lts-community-debuginfo MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-8.4-lts-community-source MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-innovation-community MySQL Cluster Innovation Relea 禁用
mysql-cluster-innovation-community-debuginfo MySQL Cluster Innovation Relea 禁用
mysql-cluster-innovation-community-source MySQL Cluster Innovation Relea 禁用
mysql-connectors-community MySQL Connectors Community 啟用
mysql-connectors-community-debuginfo MySQL Connectors Community - D 禁用
mysql-connectors-community-source MySQL Connectors Community - S 禁用
mysql-innovation-community MySQL Innovation Release Commu 禁用
mysql-innovation-community-debuginfo MySQL Innovation Release Commu 禁用
mysql-innovation-community-source MySQL Innovation Release Commu 禁用
mysql-tools-8.4-lts-community MySQL Tools 8.4 LTS Community 啟用
mysql-tools-8.4-lts-community-debuginfo MySQL Tools 8.4 LTS Community 禁用
mysql-tools-8.4-lts-community-source MySQL Tools 8.4 LTS Community 禁用
mysql-tools-community MySQL Tools Community 禁用
mysql-tools-community-debuginfo MySQL Tools Community - Debugi 禁用
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-innovation-community MySQL Tools Innovation Communi 禁用
mysql-tools-innovation-community-debuginfo MySQL Tools Innovation Communi 禁用
mysql-tools-innovation-community-source MySQL Tools Innovation Communi 禁用
mysql80-community MySQL 8.0 Community Server 禁用
mysql80-community-debuginfo MySQL 8.0 Community Server - D 禁用
mysql80-community-source MySQL 8.0 Community Server - S 禁用
[root@web ~]#
安裝MySQL
[root@web ~]# yum install mysql-community-server
啟動(dòng)MySQL服務(wù)
[root@web ~]# systemctl start mysqld
確認(rèn)MySQL正常啟動(dòng)
[root@web ~]# systemctl status mysqld
設(shè)置MySQL開(kāi)機(jī)自啟動(dòng)
[root@web ~]# systemctl enable mysqld
查看生成 MySQL root用戶(hù)臨時(shí)密碼:
[root@web ~]# grep 'temporary password' /var/log/mysqld.log
修改root用戶(hù)密碼
# 登錄數(shù)據(jù)庫(kù)
[root@web ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3
Copyright (c) 2000, 2024, 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>
# 修改root密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password@2024';
Query OK, 0 rows affected (0.01 sec)
mysql>
設(shè)置遠(yuǎn)程登錄
# 查看默認(rèn)庫(kù)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
# 選擇使用mysql庫(kù)
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>
# 查詢(xún)用戶(hù)表
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$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
# 修改root的授權(quán)
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
# 需要執(zhí)行倆次
mysql> Grant all privileges on *.* to 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql>
mysql> Grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql>
# 刷新權(quán)限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql>
# 再次查看用戶(hù)表
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | $A$005$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
| 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 |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
測(cè)試連接
# 使用其他主機(jī)進(jìn)行登錄數(shù)據(jù)庫(kù)
[root@k8s-master01 ~]# mysql -u root -p -h 192.168.1.130
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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>