Basic operations of the database

Source: Internet
Author: User

Summarize the Small Basic operation of the database, remember to always check ~

1. View the database

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Oldboy |
| Student |
| Test |
+--------------------+
5 rows in Set (0.03 sec)

2. View the current database (empty when no use database is present)

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
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. Delete Database

mysql> help drop database; (Viewing the assistance document)
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 was dropped, user privileges on the
Database is not automatically dropped. See [Help GRANT].

If EXISTS is used to prevent a 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. Connect to the database and view basic information about some databases

Use < database name > (;)

Mysql> Select User ();
+----------------+
| User () |
+----------------+
| [Email protected] |
+----------------+
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. Delete Redundant users

Drop user "user" @ "host Domain"

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)

If the drop cannot be deleted, it can be removed in the following way:

Delete from Mysql.user where user= "root" and host= "localhost"

When processing users remember to refresh the permissions flush privileges;

Basic operations of the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.