1.首先在官網(wǎng)https://dev.mysql.com/downloads/mysql/瞬女,下載相應rpm文件到Centos本地
2.下載完成后榕茧,cd 到對應路徑下,執(zhí)行如下命令
# rpm -ivh mysql-community-5.7.18-1.sles12.src.rpm
# yum install mysql-community-server
tips:安裝完成后重啟服務客给,初次安裝用押,root賬戶沒有密碼。用root賬戶進入mysql.
# sudo systemctl restart mysqld.service
# mysql -u root
3.配置遠程登錄到Mysql
3.1進入到mysql后, 執(zhí)行下面的sql語句授權可以進行遠程訪問
tips:*.*可以訪問數(shù)據(jù)庫中所有的表;用root賬戶登錄;'%'表示從任何地址連接;password即連接口令.
mysql> grant all privileges on *.* to root@'%'identified by 'password';?
3.2配置my.cnf靶剑,添加bind-address和default-character-set
# sudo vim /etc/my.cnf?
[mysqld]
#bind-address是Centos的ip地址,此地址默認端口號為3306
bind-address=xxx.xxx.xxx.xxx
[mysql]
default-character-set =utf8
3.3執(zhí)行權限分配和防火墻等命令
# sudo chown -R mysql:mysql /var/lib/mysql
# sudo firewall-cmd --zone=public --permanent --add-service=mysql
# sudo systemctl restart firewalld
# sudo systemctl restart mysqld.service
3.4客戶端遠程訪問Centos中MySql,客戶端必須要ping的通Centos的ip地址
tip:客戶端也要安裝Mysql這里就不多敘述了,反正都在上面的官網(wǎng)上找蜻拨,mac安裝mysql-xxx.dmg,windows安裝mysql-xxx.exe等等.
tip:客戶端執(zhí)行如下命令,進行遠程登錄訪問,我的客戶端是mac os 10.12.5.
tip(mac os):如果提示-bash: mysql: command not found桩引。要做個軟連接,比如mysql的路徑是:/usr/local/mysql/bin/mysql, 輸入ln -s /usr/local/mysql/bin/mysql /usr/bin
# mysql -h xxx.xxx.xxx.xxx -u root -p
輸入口令,連接成功. So,你可以在客戶端操作遠程數(shù)據(jù)庫寫sql語句了.