第一步:獲取mysql YUM源mysql
進入mysql官網獲取RPM包下載地址sql
https://dev.mysql.com/downloads/repo/yum/tcp
右擊 複製連接地址 https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmide
獲得這個 這個就是Yum倉庫的rpm包 其實就是一個下載地址測試
第二步:下載和安裝mysql源編碼
先下載 mysql源安裝包spa
[root@localhost ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm命令行
安裝mysql源3d
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm rest
第三步:在線安裝Mysql
yum -y install mysql-community-server
下載的東西比較多 要稍微等會;
第四步:啓動Mysql服務
systemctl start mysqld
第五步:設置開機啓動
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
第六步:修改root本地登陸密碼
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個臨時的默認密碼。
[root@localhost ~]# vi /var/log/mysqld.log
這裏的臨時密碼 eMV.R#mWe3ha
[root@localhost ~]# mysql -u root -p
Enter password:
輸入臨時密碼 進入mysql命令行;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ABCDabcd1234@';
Query OK, 0 rows affected (0.00 sec)
修改密碼爲 ABCDabcd1234@ (備註 mysql5.7默認密碼策略要求密碼必須是大小寫字母數字特殊字母的組合,至少8位)
第七步:設置容許遠程登陸
Mysql默認不容許遠程登陸,咱們須要設置下,而且防火牆開放3306端口;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ABCDabcd1234@' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit;
Bye
退出下;
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#
開放3306端口
第八步:配置默認編碼爲utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,以下所示:
[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 | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
第九步:測試
咱們用本機的sqlyog遠程鏈接下虛擬機裏的mysql
OK 至此 Mysql安裝配置完畢;