天天看點

MySQL資料庫遠端通路權限如何打開(兩種方法)MySQL資料庫遠端通路權限如何打開(兩種方法)

MySQL資料庫遠端通路權限如何打開(兩種方法)

下載下傳GPL版本安裝

MySQL Community Edition(GPL)

Community (GPL) Downloads

在我們使用mysql資料庫時,有時我們的程式與資料庫不在同一機器上,這時我們需要遠端通路資料庫。預設狀态下,mysql的使用者沒有遠端通路的權限。

下面介紹兩種方法,解決這一問題。

1、改表法

可能是你的帳号不允許從遠端登陸,隻能在localhost。這個時候隻要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"

mysql -u root -p 
mysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user;      

2、授權法

在安裝mysql的機器上運作:

1、d:\mysql\bin\>mysql -h localhost -u root

//這樣應該可以進入MySQL伺服器

2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION

//賦予任何主機通路資料的權限

例如,你想myuser使用mypassword從任何主機連接配接到mysql伺服器的話。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WI 
TH GRANT OPTION;      

如果你想允許使用者myuser從ip為192.168.1.6的主機連接配接到mysql伺服器,并使用mypassword作為密碼

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY 
'mypassword' WITH GRANT OPTION;      

3、mysql>FLUSH PRIVILEGES

//修改生效

4、mysql>EXIT

退出MySQL伺服器,這樣就可以在其它任何的主機上以root身份登入

以上所述是小編給大家介紹的MySQL資料庫遠端通路的權限如何打開,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對腳本之家網站的支援!

您可能感興趣的文章:

一、

MySQL

登入錯誤

mysqladmin: connect to server at 'localhost' failed

error: 'Access denied for user 'root'@'localhost' (using password: YES)'

無法修改密碼

用 service mysqld stop

mysqld_safe --skip-grant-tables &

輸入 

mysql

 -uroot -p 回車進入

>use mysql;

> update user set password=PASSWORD("newpass")where user="root";

 更改密碼為 newpassord

> flush privileges; 更新權限

> quit 退出

service mysqld restart

mysql -uroot -p新密碼進入

===========================================================

二,忘記本地root的登入密碼

解決過程:

1、編輯/etc/my.cnf

在[mysqld] 配置部分添加一行

skip-grant-tables

2、儲存後重新開機mysql

[root@localhost etc]# service mysqld restart

Shutting down MySQL.                                       [  OK  ]

Starting MySQL.                                                   [  OK  ]

3、登入

資料庫

重新設定root密碼

[root@localhost ~]# mysql -uroot -p mysql

Enter password:

直接回車進入

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.47-log Source distribution

Copyright (c) 2000, 2010, 

Oracle

 and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

+--------------------+

| Database           |

| information_schema |

| mysql              |

| test               |

3 rows in set (0.00 sec)

執行下列語句

mysql> update user set password=password("mysql") where user='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

4、删除/etc/my.cnf檔案中添加的“skip-grant-tables”行,重新開機mysql;

用新設的密碼就能正常登入了;