虛擬機器centos7安裝mysql8.x
# 刪除系統倉庫
[root@localhost ~]# rm -rf /etc/yum.repos.d/*
# CentOS 7 更換阿里雲軟體倉庫
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 檢視軟體倉庫最新情況
[root@localhost ~]# yum repolist
repolist: 16,771
# 下載wget
[root@localhost ~]# yum install -y wget
# 下載mysql源安裝包
[root@localhost ~]# wget https://dev.mysql.com/get/mysql84-community-release-el7-1.noarch.rpm
# 安裝mysql源
[root@localhost ~]# yum -y localinstall mysql84-community-release-el7-1.noarch.rpm
# 線上安裝mysql
[root@localhost ~]# yum -y install mysql-community-server
# 啟動mysql服務
[root@localhost ~]# systemctl start mysqld
# 設定開機自啟
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
# 修改root本地登入密碼
[root@localhost ~]# vi /var/log/mysqld.log
# 輸入臨時密碼,進入mysql命令列
[root@localhost ~]# mysql -u root -p
# 修改root使用者密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql_4U';
Query OK, 0 rows affected (0.01 sec)
# 建立root使用者與密碼
mysql> create user 'root'@'%' identified by 'mysql_4U';
Query OK, 0 rows affected (0.01 sec)
# 授予root使用者所有許可權
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)
# 重新整理授權
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
# 退出
mysql> exit
# 開啟防火牆3306埠
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
# 配置預設編碼為UTF-8
[root@localhost ~]# vi /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
# 重啟mysql服務
[root@localhost ~]# systemctl restart mysqld
# 檢視編碼
mysql> show variables like '%character%';
+-------------------------------------------------+--------------------------------+
| Variable_name | Value |
+-------------------------------------------------+--------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb3 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb3 |
| character_set_system | utf8mb3 |
| character_sets_dir | /usr/share/mysql-8.4/charsets/ |
| validate_password.changed_characters_percentage | 0 |
+-------------------------------------------------+--------------------------------+
9 rows in set (0.02 sec)
# 開啟navicat連線mysql
參考連結:
CentOS 7 更換軟體倉庫
centos上開啟mysql遠端訪問功能
Centos7安裝和配置Mysql5.7
阿里雲伺服器開放3306埠 外部依舊不能訪問
MySQL Community Downloads
CentOS 映象
Navicat Premium Lite 17 下載地址