# apt-get update
# apt-get install mysql-server
安裝過程會提示設置 root 密碼(若未提示,預設為空)。
# mysqladmin -u root password 'your_new_password'
/etc/mysql/my.cnf(或 my.conf),找到 bind-address = 127.0.0.1,兩種方式任選其一:-- 方式 1:註釋該行
# bind-address = 127.0.0.1
-- 方式 2:改為監聽所有介面
bind-address = 0.0.0.0
注意:不要設為 bind-address = *,舊版本不支援,會導致啟動失敗。
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
(不建議用 reload,偶爾會出現異常。)
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'root_password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
完成後,任意 IP 均可用 root 密碼遠程連接。
$ mysql -h server_ip -u root -p