MySQL 入门

2020-03-09  本文已影响0人  momo1023

登录

$ mysql -u username -p password

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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> 

查看所有数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

查看当前使用的数据库

select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

创建数据库

mysql> CREATE DATABASE faq;
Query OK, 1 row affected (0.02 sec)

选择数据库

mysql> use faq
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| faq        |
+------------+
1 row in set (0.00 sec)

创建表

mysql> CREATE TABLE IF NOT EXISTS `QA`(
    ->    `id` INT UNSIGNED AUTO_INCREMENT,
    ->    `index` VARCHAR(100) NOT NULL,
    ->    `question` VARCHAR(512) NOT NULL,
    ->    `answer` VARCHAR(512) NOT NULL,
    ->    PRIMARY KEY ( `id` )
    -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected, 1 warning (0.04 sec)

其他信息的查看

参考https://www.cnblogs.com/wanglijun/p/8883875.html

上一篇 下一篇

猜你喜欢

热点阅读