Mysql的管理

Linux系统中:mysql进入的命令为mysql -u root -p +你的mysql密码。

Mysql是如何添加用户呢?

mysql命令行下,使用use mysql;进入mysql的数据库中。然后插入信息到user表,就可以添加上用户了。

例子如下:

MariaDB [mysql]> insert into user  (host,user,password,select_priv,insert_priv,update_priv) values ('localhost','whr',password('whr123'),'Y','Y','Y');
Query OK, 1 row affected, 4 warnings (0.00 sec)
MariaDB [mysql]> select host,user,password from user;

 

常用的管理Mysql的命令:
use 数据库;(进入数据库)
MariaDB [(none)]> use mysql;
Database changed
show databases;(查看MySQL中的所有数据库)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)
show tables;(查看当前数据库中的所有表)
MariaDB [mysql]> show tables ;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.00 sec)

show columnns form 表名;(显示指定表的属性)
MariaDB [mysql]> show columns from servers;
+-------------+----------+------+-----+---------+-------+
| Field       | Type     | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+-------+
| Server_name | char(64) | NO   | PRI |         |       |
| Host        | char(64) | NO   |     |         |       |
| Db          | char(64) | NO   |     |         |       |
| Username    | char(64) | NO   |     |         |       |
| Password    | char(64) | NO   |     |         |       |
| Port        | int(4)   | NO   |     | 0       |       |
| Socket      | char(64) | NO   |     |         |       |
| Wrapper     | char(64) | NO   |     |         |       |
| Owner       | char(64) | NO   |     |         |       |
+-------------+----------+------+-----+---------+-------+
9 rows in set (0.00 sec)

show index from 表名;(显示指定表的详细索引信息,包括主键)
MariaDB [mysql]> show index from user;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| user  |          0 | PRIMARY  |            1 | Host        | A         |        NULL |     NULL | NULL   |      | BTREE      |         |               |
| user  |          0 | PRIMARY  |            2 | User        | A         |           7 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

  

 

本人是根据无情站长的博客进行学习的,原创属于无情站长,连接:https://www.cnblogs.com/skyhu365/p/10558216.html

原文地址:https://www.cnblogs.com/shy13138/p/11504945.html