码迷,mamicode.com
首页 > 数据库 > 详细

数据库的基本操作

时间:2017-09-11 13:13:27      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:row   important   query   总结   now()   rip   imp   帮助文档   back   

总结下数据库小小的基本操作,要记得时常查看~ 

1.查看数据库

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| oldboy |
| student |
| test |
+--------------------+
5 rows in set (0.03 sec)

 2.查看当前所在的数据库(没use数据库的时候显示为空)

mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.02 sec)

 

mysql> use oldboy;

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

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

3.删除database

mysql> help drop database;(查看帮助文档)
Name: ‘DROP DATABASE‘
Description:
Syntax:
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name

DROP DATABASE drops all tables in the database and deletes the
database. Be very careful with this statement! To use DROP DATABASE,
you need the DROP privilege on the database. DROP SCHEMA is a synonym
for DROP DATABASE.

*Important*: When a database is dropped, user privileges on the
database are not automatically dropped. See [HELP GRANT].

IF EXISTS is used to prevent an error from occurring if the database
does not exist.

  URL: http://dev.mysql.com/doc/refman/5.1/en/drop-database.html

 

mysql> drop database student;

Query OK, 0 rows affected (0.05 sec)

4.连接数据库,以及查看一些数据库的基本信息

use <数据库名>(;)

mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

 

mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2017-09-11 04:08:33 |
+---------------------+
1 row in set (0.00 sec)

 

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.1.73 |
+-----------+
1 row in set (0.00 sec)

    

5.删除多余的用户

drop user "user"@"主机域"

mysql> select user,host from mysql.user;
+------+--------------------------------+
| user | host |
+------+--------------------------------+
| root | 127.0.0.1 |
| | localhost |
| root | localhost |
| | vagrant-centos65.vagrantup.com |
| root | vagrant-centos65.vagrantup.com |
+------+--------------------------------+
5 rows in set (0.00 sec)

 

mysql> drop user "root"@"localhost";
Query OK, 0 rows affected (0.00 sec)

 

mysql> select user,host from mysql.user;
+------+--------------------------------+
| user | host |
+------+--------------------------------+
| root | 127.0.0.1 |
| | localhost |
| | vagrant-centos65.vagrantup.com |
| root | vagrant-centos65.vagrantup.com |
+------+--------------------------------+
4 rows in set (0.00 sec)

如果drop删除不了,可以用下面方式删除:

  delete from mysql.user where user="root" and host="localhost"

处理用户的时候记得刷新权限  flush privileges;

数据库的基本操作

标签:row   important   query   总结   now()   rip   imp   帮助文档   back   

原文地址:http://www.cnblogs.com/shadowsmile/p/7504373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!