[root@centos02 ~]
[root@centos02 ~]
Enter password:
[root@centos02 ~]
mysql> STATUS;
--------------
mysql Ver 14.14 Distrib 5.6.36, for Linux (x86_64) using EditLine wrapper
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.36 Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 2 hours 39 min 36 sec
Threads: 2 Questions: 12 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.001
--------------
mysql> EXIT
Bye
[root@centos02 ~]
初始化后的MySQL服务器,默认建立了四个库:test、mysql、information_schema和performance_schema(其中mysql库是
正常运行所需的库,其中包含用户认证相关的表)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
操作之前需先使用USE语句切换到所使用的库
mysql> USE mysql;
Database changed
mysql> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
…… //省略部分内容
| user |
+---------------------------+
28 rows in set (0.00 sec)
MySQL数据库的数据文件存放在/usr/local/mysql/data目录下,每个数据库对应一个子目录,
用于存放数据表文件。每个数据表对应为三个文件,扩展名分别为”.frm“、”.myd“、”.myi“。
需要指定”库名.表名“作为参数;若只指定表名,则需先通过USE语句切换到目标库
mysql> USE mysql;
Database changed
mysql> DESCRIBE user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
…… //省略部分内容
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
43 rows in set (0.00 sec)
mysql> CREATE DATABASE auth;
刚创建的数据库是空的,其中不包含任何表,在/usr/local/mysql/data目录下会自动生成一个与新建的库名相同的文件夹
CREATE TABLE 表名 (字段1名称 类型, 字段2名称 类型, ……, PRIMARY KEY (主键名))
mysql> USE auth;
Database changed
mysql> CREATE TABLE users (user_name CHAR(16) NOT NULL, user_passwd CHAR(48) DEFAULT '', PRIMARY KEY (user_name));
Query OK, 0 rows affected (0.01 sec)
mysql> DROP TABLE auth.users;
Query OK, 0 rows affected (0.00 sec)
mysql> DROP DATABASE auth;
Query OK, 0 rows affected (0.00 sec)