1 登录数据库
格式: mysql -h主机地址 -u用户名 -p用户密码–P端口 –D数据库–e “SQL 内容”
mysql -uroot -p 数据库名称
[root@www.cndba.cn/dave mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 11
Server version: 5.5.5-10.2.12-MariaDB-log MariaDB Server
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>
2 查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
3 创建数据库
mysql> create database cndba;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| cndba |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
对应的文件会在参数文件中指定的data dir目录下生成:
[root@Dave data]# pwd
/mysql/data
[root@Dave data]# ls
aria_log.00000001 Dave.err ibdata1 ibtmp1 mysql-bin.000001 mysql-bin.000004
aria_log_control Dave.pid ib_logfile0 multi-master.info mysql-bin.000002 mysql-bin.index
cndba ib_buffer_pool ib_logfile1 mysql mysql-bin.000003 performance_schema
[root@Dave data]# cd cndba
[root@Dave cndba]# ls
db.opt
[root@Dave cndba]#
4 选择数据库
mysql> use cndba
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| cndba |
+------------+
1 row in set (0.00 sec)
5 删除数据库
mysql> drop database cndba;
Query OK, 0 rows affected (0.00 sec)
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'database' at line 1
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
6 退出数据库
mysql> exit/quit;
7 其他信息
显示当前mysql版本和当前日期:select version(),current_date;
查询时间:select now();
查询当前用户:select user();
查询数据库版本:select version();
查询当前使用的数据库:select database();
mysql> select version(),current_date;
+---------------------+--------------+
| version() | current_date |
+---------------------+--------------+
| 10.2.12-MariaDB-log | 2018-01-30 |
+---------------------+--------------+
1 row in set (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-01-30 23:23:28 |
+---------------------+
1 row in set (0.00 sec)
mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> select version();
+---------------------+
| version() |
+---------------------+
| 10.2.12-MariaDB-log |
+---------------------+
1 row in set (0.00 sec)
mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> use mysql;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mysql |
+------------+
1 row in set (0.00 sec)
版权声明:本文为博主原创文章,未经博主允许不得转载。