最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mysql命令行連接遠程/本地數(shù)據(jù)庫詳解

 更新時間:2023年05月05日 11:45:02   作者:小浪zoom  
新使用MySQL,說起來是個簡單的事情,,但是卻費了些周折,下面這篇文章主要給大家介紹了關于Mysql命令行連接遠程/本地數(shù)據(jù)庫的相關資料,文中介紹的非常詳細,需要的朋友可以參考下

Mysql 命令行 連接本地數(shù)據(jù)庫

MySQL登錄

  • mysql -uroot -p密碼
  • mysql -hip -uroot -p連接目標的密碼
  • mysql --host=ip --user=root --password=連接目標的密碼
C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3306 -p                                                                                                      
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.17 MySQL Community Server (GPL)      
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye
C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3308 -p                                                                                                      
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.5.61 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.  
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit 
Bye
C:\Users\Administrator>mysql -h 127.0.0.1 -uroot --port=3307 -p                                                                                                      
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> exit
Bye

Mysql 命令行 連接遠程數(shù)據(jù)庫

連接 遠程的數(shù)據(jù)庫

mysql --host=ip --user=root --password=連接目標的密碼

┌──(root?kali)-[~]
└─# mysql -h 69.45.123.1 -uroot --port=3307 -p
Enter password: 
ERROR 1130 (HY000): Host '69.45.123.128' is not allowed to connect to this MySQL server

有兩個方法

如果 你的 mysql 數(shù)據(jù)庫沒有 密碼 最好創(chuàng)建一個一密碼

update mysql.user set authentication_string=password('新密碼') where user='用戶名' and Host ='localhost';
update mysql.user set authentication_string=password('admin') where user='用戶名' and Host ='localhost';

1.改表法

是因為 root 帳號不允許從遠程登陸,只能在localhost。這個時候只要在localhost的那臺電腦,登入mysql后,更改 “mysql” 數(shù)據(jù)庫里的 “user” 表里的 “host” 項,從"localhost"改為"%"

C:\Users\Administrator>mysql -uroot -p -P3306
Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql; # 使用數(shù)據(jù)庫
Database changed
mysql> select user,password,host from user where user='root'; # 先查詢下 有權限的 用戶 的 host 是什么
+------+-------------------------------------------+-----------+
| user | password                                  | host      |
+------+-------------------------------------------+-----------+
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | localhost |
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | 127.0.0.1 |
| root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | ::1       |
+------+-------------------------------------------+-----------+
3 rows in set (0.00 sec)
# 修改 "mysql" 數(shù)據(jù)庫里的 "user" 表里的 "host" 項,從"localhost"改為"%"
mysql> update user set host = '%' where user = 'root' and host='localhost'; 
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0
mysql> flush privileges; # 刷新一下 mysql的緩存
Query OK, 0 rows affected (0.00 sec)

執(zhí)行操作之后 重啟服務器

如果有需要 改回來 在使用 數(shù)據(jù)庫之后 把 “mysql” 數(shù)據(jù)庫里的 “user” 表里的 “host” 項 從"%“改為"localhost” 之后刷新一下緩存之后 重啟 mysql 服務 即可

mysql> use mysql; # 使用數(shù)據(jù)庫
Database changed
mysql> update user set host = 'localhost' where user = 'root' and host='%'; 
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 0
mysql> flush privileges; # 刷新一下 mysql的緩存
Query OK, 0 rows affected (0.00 sec)

2. 授權法。例如,你想 某個用戶名 比如 myuser 和對應的密碼 從任何主機連接到mysql服務器的話。

/*myuser mypassword 為對應的 用戶迷宮和密碼 */
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;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.3' IDENTIFIED BY '1235' WITH GRANT OPTION;
mysql> flush privileges; # 刷新一下 mysql的緩存
Query OK, 0 rows affected (0.00 sec)

取消授權

# 查看授權的所有用戶
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;  
+---------------------------+
| query                     |
+---------------------------+
| User: 'root'@'127.0.0.1'; |
| User: 'root'@'::1';       |
| User: ''@'localhost';     |
| User: 'root'@'localhost'; |
+---------------------------+
4 rows in set (0.00 sec)

# revoke all on *.* from 'username'@'%';  username為指定的用戶,%為任意登錄的地址。
mysql> revoke all on *.* from 'root'@'192.168.1.3';     
Query OK, 0 rows affected (0.00 sec)

# 然后再次 
mysql> flush privileges; # 刷新一下 mysql的緩存
Query OK, 0 rows affected (0.00 sec)

然后 重啟 mysql 服務

總結

到此這篇關于Mysql命令行連接遠程/本地數(shù)據(jù)庫的文章就介紹到這了,更多相關Mysql命令行連接數(shù)據(jù)庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • linux下講解MySQL安裝與登錄方法

    linux下講解MySQL安裝與登錄方法

    MySQL安裝文件已被廣泛應用但是也在不斷的更新,這里介紹MySQL安裝文件設置使用,幫助大家安裝更新MySQL安裝文件系統(tǒng)。
    2010-11-11
  • 淺談Mysql主鍵索引與非主鍵索引區(qū)別

    淺談Mysql主鍵索引與非主鍵索引區(qū)別

    本文主要介紹了ysql主鍵索引與非主鍵索引區(qū)別,文中介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-09-09
  • MySQL死鎖日志的實例分析技巧總結

    MySQL死鎖日志的實例分析技巧總結

    MySQL死鎖是線上經(jīng)常遇到的現(xiàn)象,MySQL死鎖日志分析方法有助于研發(fā)快速提取信息,提高分析效率,通過了解死鎖觸發(fā)條件、檢測機制及鎖類型,結合日志分析工具,可以更有效地解決死鎖問題
    2024-11-11
  • MySQL配置文件my.cnf與my.ini的區(qū)別

    MySQL配置文件my.cnf與my.ini的區(qū)別

    在使用MySQL時,我們需要對其進行配置,以滿足我們的需求,本文主要介紹了MySQL配置文件my.cnf與my.ini的區(qū)別,具有一定的參考價值,感興趣的可以了解一下
    2024-03-03
  • 多次執(zhí)行mysql_fetch_array()的指針歸位問題探討

    多次執(zhí)行mysql_fetch_array()的指針歸位問題探討

    多次執(zhí)行mysql_fetch_array(),在第二次執(zhí)行的時候,如果不加處理,就不會輸出任何內(nèi)容,這種情況下只需要對循環(huán)指針進行復位即可,感興趣的朋友可以了解下啊,或許對你有所幫助
    2013-01-01
  • 同時運行多個MySQL服務器的方法

    同時運行多個MySQL服務器的方法

    在同一臺機器上運行多個有些情況下你可能想要在同一臺機器上運行多個服務器。例如,你可能想要測試一個新的MySQL版本而讓你現(xiàn)有生產(chǎn)系統(tǒng)的設置不受到干擾, 或你可能是想要為不同的客戶提供獨立的MySQL安裝一個因特網(wǎng)服務供應商。
    2008-05-05
  • MySQL中使用distinct單、多字段去重方法

    MySQL中使用distinct單、多字段去重方法

    多個字段拼接去重是指將多個字段的值按照一定的規(guī)則進行拼接,并去除重復的拼接結果,本文主要介紹了MySQL中使用distinct單、多字段去重方法,感興趣的可以了解一下
    2024-05-05
  • 教你解決往mysql數(shù)據(jù)庫中存入漢字報錯的方法

    教你解決往mysql數(shù)據(jù)庫中存入漢字報錯的方法

    這篇文章主要介紹了Mysql基礎之教你解決往數(shù)據(jù)庫中存入漢字報錯的方法,文中有非常詳細的代碼示例,對正在學習mysql的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-05-05
  • MySQL庫表名大小寫的選擇

    MySQL庫表名大小寫的選擇

    一般在數(shù)據(jù)庫使用規(guī)范中,我們都會看到這么一條:庫名及表名一律使用小寫英文。你有沒有思考過,為什么推薦使用小寫呢?庫表名是否應該區(qū)分大小寫呢?帶著這些疑問,我們一起來看下本篇文章。
    2021-06-06
  • ORM模型框架操作mysql數(shù)據(jù)庫的方法

    ORM模型框架操作mysql數(shù)據(jù)庫的方法

    ORM 全稱是(Object Relational Mapping)表示對象關系映射; 通俗理解可以理解為編程語言的虛擬數(shù)據(jù)庫;這篇文章主要介紹了ORM模型框架操作mysql數(shù)據(jù)庫的方法,需要的朋友可以參考下
    2021-07-07

最新評論

巴楚县| 南澳县| 剑川县| 辉南县| 海林市| 水富县| 石楼县| 玉田县| 肇源县| 宁阳县| 邓州市| 石渠县| 宁明县| 金川县| 南溪县| 武平县| 黄浦区| 阜康市| 碌曲县| 淮滨县| 连城县| 称多县| 汉源县| 凤城市| 观塘区| 安岳县| 浦东新区| 凤阳县| 东乌珠穆沁旗| 普兰县| 旬阳县| 鹤峰县| 昔阳县| 修文县| 务川| 广元市| 漯河市| 沙河市| 景洪市| 惠安县| 织金县|