需求描述:
mysql客戶端,可以在登錄到mysql數據庫時,指定要連接到哪個數據庫
這里進行一個測試。
測試過程:
1.mysql通過-D參數指定連接到test數據庫
[mysql@redhat6 scripts]$ mysql -uroot -p -D test Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [mysql@redhat6 scripts]$ mysql -uroot -p -D test Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.5.57-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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> select database(); +------------+ | database() | +------------+ | test | +------------+ 1 row in set (0.00 sec)
備注:通過在-D參數后面指定數據庫名字,就連接到了test數據庫。
2.通過-D參數,連接到test01數據庫
[mysql@redhat6 scripts]$ mysql -uroot -p -D test01 Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 5.5.57-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, 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> select database(); +------------+ | database() | +------------+ | test01 | +------------+ 1 row in set (0.00 sec) mysql>
備注:通過在-D參數后面指定數據庫名字,就連接到了test01數據庫。
小結:通過-D 參數指明要直接連接到哪個數據庫。
文檔創建時間:2018年3月20日11:37:27