本章節主要講解的是在虛擬機centOs7版本以上安裝mysql5.6版本,親測能夠直接使用,有須要幫助的小夥伴能夠加本人QQ2246451792@qq.com!!!!css
卸載centOs7自帶的mariadb命令:
rpm -qa | grep mariadb
rpm -e --nodeps 文件名node
1.新開的雲服務器,須要檢測系統是否自帶安裝mysqlmysql
# yum list installed | grep mysql
2.若是發現有系統自帶mysql,果斷這麼幹sql
# yum -y remove 文件名
3.隨便在你存放文件的目錄下執行,這裏解釋一下,因爲這個mysql的yum源服務器在國外,因此下載速度會比較慢,還好mysql5.6只有79M大,而mysql5.7就有182M了,因此這是我不想安裝mysql5.7的緣由shell
# wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
4.接着執行這句,解釋一下,這個rpm還不是mysql的安裝文件,只是兩個yum源文件,執行後,在/etc/yum.repos.d/ 這個目錄下多出mysql-community-source.repo和mysql-community.repo數據庫
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
5.這個時候,能夠用yum repolist mysql這個命令查看一下是否已經有mysql可安裝文件windows
#yum repolist all | grep mysql
6.安裝mysql 服務器命令(一路yes):安全
# yum install mysql-community-server
7.安裝成功後bash
# service mysqld start
8.因爲mysql剛剛安裝完的時候,mysql的root用戶的密碼默認是空的,因此咱們須要及時用mysql的root用戶登陸(第一次回車鍵,不用輸入密碼),並修改密碼服務器
# mysql -u root
# use mysql;
#update user set password=PASSWORD('admin123') where user='root';
# flush privileges;
# exit;
9.查看mysql是否自啓動,而且設置開啓自啓動命令
# chkconfig --list | grep mysqld # chkconfig mysqld on
10.mysql安全設置(系統會一路問你幾個問題,看不懂複製以後翻譯,基本上一路yes):
# mysql_secure_installation
登錄:
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.60 MySQL Community Server (GPL) by Remi
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| fgf |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql>
使用mysql數據庫(真正的數據庫,而非數據庫軟件),將全部數據庫的全部表(*.*)的全部權限(all privileges),授予經過任何ip(%)訪問的root用戶,密碼爲123456,最後刷新(flush privileges)便可。
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
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
開放防火牆端口:
先查看防火牆是否開啓了3306端口:
1
|
firewall-cmd --permanent --query-port=3306
/tcp
|
打印結果以下:
no
表示沒有開放3306端口,那麼添加下該端口:
1
|
firewall-cmd --permanent --add-port=3306
/tcp
|
打印結果以下:
success
從新加載防火牆策略:
1
|
firewall-cmd --reload
|
執行成功後,查看10086端口是否被開啓:
1
|
firewall-cmd --permanent --query-port=3306
/tcp
|
打印結果以下:
yes
最後一步配置虛擬機NAT設置(具體流程省略,主要是放行端口號)
在windows下,我用 navicat測試:
------mysql 相關命令: service mysqld restart ;service mysqld status ;service mysqld start