1:獲取mysql YUM源html
進入mysql官網獲取RPM包下載地址java
https://dev.mysql.com/downloads/repo/yum/(根據自身的Linux操做系統版原本下載對應的mysql版本)mysql
右擊 複製連接地址 https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmsql
獲得這個 這個就是Yum倉庫的rpm包 其實就是一個下載地址bash
2:下載和安裝mysql源tcp
先下載 mysql源安裝包ide
[root@localhost ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm測試
-bash: wget: 未找到命令編碼
咱們先安裝下wget spa
yum -y install wget
而後執行 wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安裝mysql源
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
3:在線安裝Mysql
yum -y install mysql-community-server
下載的東西比較多 要稍微等會;
4:啓動Mysql服務
systemctl start mysqld
5:設置開機啓動
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl daemon-reload
6:修改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 'Caofeng2012@';
Query OK, 0 rows affected (0.00 sec)
修改密碼爲 Caofeng2012@ (備註 mysql5.7默認密碼策略要求密碼必須是大小寫字母數字特殊字母的組合,至少8位)
7:設置容許遠程登陸
Mysql默認不容許遠程登陸,咱們須要設置下,而且防火牆開放3306端口;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Caofeng2012@' 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端口
8:配置默認編碼爲utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,以下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
[root@localhost ~]# vi /etc/my.cnf
編輯保存完 重啓mysql服務;
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]#
查看下編碼:
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)
9:測試
咱們用本機的sqlyog遠程鏈接下虛擬機裏的mysql
詳細請參考:http://blog.java1234.com/blog/articles/308.html