Mysql 數據庫創建與刪除(基礎2)
阿新 • • 發佈:2018-04-14
copyright pass monitor current com put int -- BE
創建數據庫 語法:
pyvip@Vip:~$ mysql -uxlong -pqwe123 #使用普通用戶登錄Mysql mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.21-0ubuntu0.16.04.1 (Ubuntu) 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> create database mybd1; #創建一個名為 "mydb1" 的數據庫 Query OK, 1 row affected (0.00 sec) mysql> show databases; #查看創建的數據庫 "mydb1" +--------------------+ | Database | +--------------------+ | information_schema | | mybd1 | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> drop database mybd1; #刪除名為 "mydb1" 的數據庫,也可以使用這樣語法刪除數據庫(drop database if exists mydb1;) Query OK, 0 rows affected (0.00 sec) mysql> show databases; #查看刪除結果, "mydb1" 數據庫已經被刪除了 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> SELECT DATABASE(); #查看當前在數據庫的目錄,類似linux中的pwd。 +------------+ #這個結果表示,當前只是在mysql大廳裏面,還沒有進入數據庫中。 | DATABASE() | +------------+ | NULL | +------------+ 1 row in set (0.01 sec)
進入數據庫:
mysql> create database mydb123; #創建一個數據庫 Query OK, 1 row affected (0.00 sec) mysql> show databases; #查看創建結果,mydb123 已經創建完成 +--------------------+ | Database | +--------------------+ | information_schema | | mydb123 | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) mysql> use mydb123; #進入創建的mydb123 數據庫 Database changed mysql> select database(); #查看當前所在數據庫目錄,已經進入mydb123 數據庫。 +------------+ | database() | +------------+ | mydb123 | +------------+ 1 row in set (0.00 sec) mysql>
Mysql 數據庫創建與刪除(基礎2)