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