今天配置伺服器的資料庫,之前有印象,所以直接就是按照下面的方法,在伺服器上新增了乙個user用於遠端連線。
-- 檢視user
mysql> use mysql;
mysql> select host,user,password from user;
-- 建立新user
mysql> create user 'username' identified by 'userpwd';
# 或mysql> grant all privileges on *.* to 'username'@'***.***.***.***' identified by 'userpwd'; -- 如果任何ip可連線,則@'%'
-- 修改使用者名稱
mysql> rename user 'oldname' to 'newname';-- mysql5之前需要使用update更新user表
-- 刪除user
mysql> drop user newuser; -- mysql5之前刪除使用者時必須先使用revoke 刪除使用者許可權,然後刪除使用者,mysql5之後drop 命令可以刪除使用者的同時刪除使用者的相關許可權
-- 更改密碼
mysql> update mysql.user set password=password('***x') where user='username';
-- 檢視使用者許可權
mysql> show grants for 'username';
-- 賦予許可權
mysql> grant select on dbname.* to 'username';
-- **許可權
mysql> revoke select on dbname.* from 'username';
-- 重新整理生效
mysql> flush privileges;
按照以上建立user的方式,檢視使用者表,有相應的記錄後,一般是沒有問題了。但是我在客戶機還是無法連線。
排除了以下可能的問題:
1、防火牆禁止了3306埠訪問。不過大多數linux的防火牆預設的是不活躍的。像我這裡的ubuntu的ufw,『ufw status』顯示的是『inactive』。
2、埠不是3306。檢視配置檔案my.cnf,埠的確是3306,。
後來網上找到了這篇部落格博主列出了很多可能的問題,其中提到了my.cnf配置檔案中bind_address項,我看了該項的注釋,果然是它的問題。
[mysqld]
# instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure
bind-address = 127.0.0.1
將其注釋掉之後,連線成功!
希望能給大家節省點時間
遠端無法連線MySQL資料庫
我們在從資料庫中獲取資料的時候,使用本機資料庫沒有問題,但是使用虛擬機器或者全程資料庫時資料庫使用者和密碼輸入正確的情況下資料獲取不到,後台也顯示我發連線資料庫報錯,此時我們有以下集中解決方式 我這裡使用的是虛擬機器上的mysql少數原因是因為本機服務沒啟動 如果啟動1方法服務無效,那麼我們就要檢視...
解決MySQL資料庫無法遠端連線問題
在使用windows系統遠端連線linux下的mysql資料庫時,提示無法連線。解決方法如下 第 一 允許mysql資料庫被遠端連線vim etc mysql mysql.conf d mysqld.cnf 注釋掉以下一行,使用 號注釋 bind address 127.0.0.1 重啟服務 ser...
無法連線 遠端IP上的mysql 資料庫
如果你想連線你的mysql的時候發生這個錯誤 以下是引用內容 error 1130 host 192.168.1.3 is not allowed to connect to this mysql server 解決方法 1。改表法。可能是你的帳號不允許從遠端登陸,只能在localhost。這個時候...