1.首先確認服務器出於安全的狀態,也就是沒有人可以任意地鏈接MySQL數據庫。mysql
由於在從新設置MySQL的root密碼的期間,MySQL數據庫徹底出於沒有密碼保護的狀態下,其餘的用戶也能夠任意地登陸和修改MySQL的信息。能夠採用將MySQL對外的端口封閉,而且中止Apache以及全部的用戶進程的方法實現服務器的準安全狀態。最安全的狀態是到服務器的Console上面操做,而且拔掉網線。sql
2.修改MySQL的登陸設置:數據庫
1
|
vim /etc/my.cnf
|
在[mysqld]的段中加上一句:skip-grant-tablesvim
例如:安全
1
2
3
4
|
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-
grant
-tables
|
保存而且退出vi。服務器
3.從新啓動mysqldsocket
1
2
3
|
service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
|
4.登陸並修改MySQL的root密碼tcp
mysqlui
1
2
3
4
5
6
7
8
9
10
11
|
Welcome
to
the MySQL monitor. Commands
end
with
;
or
\g.
Your MySQL
connection
id
is
3
to
server version: 3.23.56
Type ‘help;
' or ‘\h'
for
help. Type ‘\c
' to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> UPDATE user SET Password = password ( '
new-
password
' ) WHERE User = '
root' ;
Query OK, 0
rows
affected (0.00 sec)
Rows
matched: 2 Changed: 0 Warnings: 0
mysql> flush
privileges
;
Query OK, 0
rows
affected (0.01 sec)
mysql> quit
|
5.將MySQL的登陸設置修改回來spa
1
|
vim /etc/my.cnf
|
將剛纔在[mysqld]的段中加上的skip-grant-tables刪除
保存而且退出vim
6.從新啓動mysqld
1
2
3
|
service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
|
容許遠程鏈接
1
|
GRANT
ALL
PRIVILEGES
ON
.
TO
root@
'%'
IDENTIFIED
BY
‘your
password
';
|
%表示多有機器。
打開3306端口,爲防火牆設置例外,放行3306.
打開iptables的配置文件:
1
|
vi /etc/sysconfig/iptables
|
在中間添加一行
1
|
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
|
所有修改完以後重啓iptables:
1
|
service iptables restart
|