签到成功

知道了

CNDBA社区CNDBA社区

MariaDB 常见的数据库级操作

2018-02-06 15:58 2468 0 原创 MySQL
作者: dave

1 登录数据库

格式: mysql -h主机地址 -u用户名 -p用户密码–P端口 –D数据库–e “SQL 内容”
mysql -uroot -p 数据库名称http://www.cndba.cn/dave/article/2631

http://www.cndba.cn/dave/article/2631
http://www.cndba.cn/dave/article/2631
http://www.cndba.cn/dave/article/2631

[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目录下生成:http://www.cndba.cn/dave/article/2631http://www.cndba.cn/dave/article/2631http://www.cndba.cn/dave/article/2631http://www.cndba.cn/dave/article/2631http://www.cndba.cn/dave/article/2631http://www.cndba.cn/dave/article/2631

[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)

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2262
    原创
  • 3
    翻译
  • 579
    转载
  • 192
    评论
  • 访问:8089984次
  • 积分:4350
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ