用 phpMyAdmin 以 Web 方式建立、复制、删除、管理 MariaDB 或 MySQL 数据库当然相当方便。但有时还需在 Ubuntu Server 14.04 下以命令行方式操作、管理 MariaDB 或 MySQL 数据库。以下将讲解操作、管理 MariaDB 或 MySQL 数据库的一些最常用命令。  
1、连接、登陆数据库服务器 
- root:# mysql -u root -p
 
 - Enter password:          #键入 MariaDB 或 MySQL 的 root 用户密码
 
 - Welcome to the MariaDB monitor.  Commands end with ; or \g.
 
 - Your MariaDB connection id is 836
 
 - Server version: 5.5.40-MariaDB-0ubuntu0.14.04.1 (Ubuntu)
 
  
- Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
 
  
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
  
- MariaDB [(none)]>
 
  复制代码 2、创建新数据库- MariaDB [(none)]> create database test;
 
 - Query OK, 1 row affected (0.00 sec)
 
  
- MariaDB [(none)]>
 
  复制代码 3、切换数据库 
- MariaDB [(none)]> use test;
 
 - Database changed
 
 - MariaDB [test]>
 
  复制代码 4、导入备份数据- MariaDB [documents]> source  /var/test/test.sql;
 
 - Query OK, 0 rows affected (0.00 sec)
 
  
- Query OK, 0 rows affected (0.00 sec)
 
  
- Query OK, 0 rows affected (0.00 sec)
 
  
- Query OK, 0 rows affected (0.00 sec)
 
  
- Query OK, 0 rows affected (0.00 sec)
 
  
- Query OK, 0 rows affected, 1 warning (0.00 sec)
 
  
- Query OK, 0 rows affected (0.03 sec)
 
  
- Query OK, 3 rows affected (0.00 sec)
 
 - Records: 3  Duplicates: 0  Warnings: 0
 
  
- MariaDB [documents]> 
 
  复制代码 5、删除数据库 
- MariaDB [test]> drop database test;
 
 - Query OK, 0 rows affected (0.00 sec)
 
  
- MariaDB [(none)]>
 
  复制代码 6、退出数据库服务器 
- MariaDB [(none)]> exit
 
 - Bye
 
 - root:#
 
  复制代码 
版权声明: 
本文为独家原创稿件,版权归 德云社区,未经许可不得转载;否则,将追究其法律责任。 
 
 |