首先是安裝 CentOS7 安裝mysql(YUM源方式) 1.下載mysql源安裝包 $ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2.安裝mysql源 $ yum localinstall mysql57-community-release-el7-8.noarch.rpm 3.檢查mysql源是否安裝成功 $ yum repolist enabled | grep "mysql.*-community.*" 4.修改yum源 【可跳過】 $ vim /etc/yum.repos.d/mysql-community.repo 改變默認安裝的mysql版本。好比要安裝5.6版本,將5.7源的enabled=1改爲enabled=0。而後再將5.6源的enabled=0改爲enabled=1便可。 備註:enabled=1表示即將要安裝的mysql版本,這個文件也能夠不修改,默認安裝mysql最高版本 5.安裝MySQL 這一步纔是真正安裝mysql $ yum install mysql-community-server 6.啓動MySQL服務並設置開機啓動 $ systemctl start mysqld $ systemctl enable mysqld $ systemctl daemon-reload 7.端口開放 $ firewall-cmd --zone=public --add-port=3306/tcp --permanent $ firewall-cmd --reload 8.修改root本地登陸密碼 注意 若是安裝的是5.6版本,默認密碼爲空!!!!!!!!!!!! 1)查看mysql密碼 $ grep 'temporary password' /var/log/mysqld.log 2)鏈接mysql $ mysql -uroot -p 3)修改密碼【注意:後面的分號必定要跟上】 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 或者: mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); mysql> show variables like '%password%'; 安裝成功以後 須要設置 一下host 才能夠遠程訪問 -----選擇mysql庫 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 -----查詢host mysql> select host from user; +-----------+ | host | +-----------+ | % | | 127.0.0.1 | | ::1 | | localhost | | monkey | | monkey | +-----------+ 6 rows in set (0.00 sec) -------更新 host 爲 通用 mysql> update user set host '%' where user ='root'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''%' where user ='root'' at line 1 mysql> quit Bye -------重啓服務 [root@monkey /]# service mysqld restart Redirecting to /bin/systemctl restart mysqld.service