- 第一步就是看linu是否安裝了mysql,經過rpm -qa|grep mysql查看到centos下安裝了mysql5.1,那就開始卸載咯
centos6.5下yum安裝mysql5.6
2 接下來就是卸載mysql5.1了,命令:rpm -e mysql-libs --nodeps
3 yum中之后mysql5.1,安裝還是5.1,現在就要去增加一個新的repo
命令:rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
4 一共需要增加兩個repo,現在增加另一個
命令:rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
5 現在查看一些是否增加成功了
命令:yum --enablerepo=remi,remi-test list mysql mysql-server
6 接下來就是安裝mysql5.56了
命令:yum --enablerepo=remi,remi-test install mysql mysql-server
7出現這個東西的時候一定要選擇y。不然神都救不了你,就要重新安裝了
8:看到下面這個圖片證明你的mysql安裝成功了
9 接下來需要啟動一下mysql
命令:/etc/init.d/mysqld start
10 下面這條命令設置開機自啟動,省的我們每次開機就去啟動一下mysql了
命令:chkconfig --levels 345 mysqld on
11 要啟用MySQL 安全設置請輸入以下命令
命令:/usr/bin/mysql_secure_installation
一直選 y
12 到這里就要驗證一下mysql是否安裝成功了。如果輸入看到以下界面的話,那么你就安裝成功了。犒勞一下自己吧。
連接數據庫命令:mysql -u用戶,-p密碼
mysql默認端口是3306,如果需要修改端口
如需要修改端口:
//登陸mysql
[root@pingxiang ~]# mysql -uroot –p
//查看端口
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
//修改etc文件夾下的my.cnf
[root@pingxiang etc]# vi my.cnf
[mysqld]
port=3560
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
user=mysql
# Semisynchronous Replication
# http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html
# uncomment next line on MASTER
;plugin-load=rpl_semi_sync_master=semisync_master.so
# uncomment next line on SLAVE
;plugin-load=rpl_semi_sync_slave=semisync_slave.so
# Others options for Semisynchronous Replication
;rpl_semi_sync_master_enabled=1
;rpl_semi_sync_master_timeout=10
;rpl_semi_sync_slave_enabled=1
# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html
;performance_schema
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
~
~
~
"my.cnf" 38L, 1093C
//初始情況下文件默認端口是3306,故沒有port=端口,要自己添加進去
按ESC鍵 跳到命令模式
:w 保存文件但不退出vi
:wq 保存文件並退出vi
//重啟mysql
[root@pingxiang etc]# /etc/init.d/mysqld restart
//出現以下信息說明重啟成功
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
//登陸mysql,查看端口
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3560 |
+---------------+-------+
1 row in set (0.00 sec)
Lunix 允許開放端口:
命令:vi /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Wed Aug 15 18:07:41 2018
*filter
:INPUT ACCEPT [6:384]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6:2572]
#-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6037 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Wed Aug 15 18:07:41 2018
~
~
~
~
"/etc/sysconfig/iptables" 20L, 848C
阿里雲允許開放端口:
可百度查詢如何設置阿里雲允許端口開放(因為我自己用的是阿里雲服務器,其他服務器好像不用這樣做)
Mysql允許遠程連接
先登陸mysql mysql -u用戶 -p密碼
然后執行命令: grant all privileges on *.* to 'root'@'%' identified by 'root';
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)
好了,可以用navicat連接了,(我用navicat,很方便),祝大家都能一次性安裝成功