mysql 建立使用者

2022-01-31 04:24:46 字數 1285 閱讀 4713

管理員方式開啟cmd命令提示符進入mysql的bin目錄下

一、以管理員身份登入mysql

密碼不隱藏的登入方式:mysql -u root -p 123456

密碼隱藏的登入方式:mysql -u root -p 123456

二、選擇mysql資料庫

use mysql

三、建立使用者並設定密碼

create user '使用者名稱'@'localhost' identified by '密碼'

此處的localhost 指的是只能在mysql服務端所在伺服器登入,需要在其他電腦登入,可以換成 %

四、使操作生效

flush privileges

五、建立乙個測試資料庫

create database testdb

六、為使用者testuser賦予運算元據庫testdb的所有許可權

grant all privileges on testdb.*  to 'testuser'@'localhost' identified  by 'password'

七、使操作生效

flush privileges

八、用新使用者登入

mysql -u testuser -p

允許使用者從遠端訪問資料庫的方法

1。 改表法。可能是你的帳號不允許從遠端登陸,只能在localhost。

這個時候只要在localhost的那台電腦,登入mysql後,更改 "mysql" 資料庫裡的 "user" 表裡的 "host" 項,從"localhost"改稱"%"

mysql -uroot -p

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

2. 授權法。例如,你想myuser使用mypassword從任何主機連線到mysql伺服器的話。

grant all privileges on *.* to 'myuser'@'%' identified by 'mypassword' with grant option;

如果你想允許使用者myuser從ip為192.168.1.3的主機連線到mysql伺服器,並使用mypassword作為密碼

grant all privileges on *.* to 'root'@'192.168.1.3' identified by 'mypassword' with grant option;

原文部落格:

mysql 建立使用者指令碼 Mysql使用者建立指令碼

我試圖自動化mysql使用者建立過程。我想到建立乙個包含mysql使用者建立語句的臨時檔案,那麼我會這樣稱呼 mysql u root proot 這裡是我的臨時檔案的內容 drop database if exists mytestdatabase create database mytestda...

mysql 建立使用者

mysql grant all privileges on to root identified by with grant option query ok,0 rows affected 0.02 sec 表示是所有的外部機器,如果指定某一台機,就將 改為相應的機器名 mysql grant al...

MYSQL 建立使用者

一,建立使用者 命令 create user username host identified by password 說明 username 你將建立的使用者名稱,host 指定該使用者在哪個主機上可以登陸,如果是本地使用者可用localhost,如果想讓該使用者可以從任意遠端主機登陸,可以使用萬...