mysql命令使用

[root@b ~]# mysql -uroot -pxxxxxxxx          #mysql登陆方式
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> show databases;              #查看所有的数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)

mysql> use mysql;                #进入mysql数据库;
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> show tables;            #查看数据库里有多少张表
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| help_topic |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| user |
+---------------------------+
11 rows in set (0.00 sec)

mysql> create database lisi;        #创建名为lisi的数据库
Query OK, 1 row affected (0.06 sec)

mysql> create table t1 (id varchar(20),name varchar(20));    #创建名为t1表,并创建两个字
Query OK, 0 rows affected (0.08 sec)

mysql> insert into t1 values("1","hello");          #向表中插入数据
Query OK, 1 row affected (0.01 sec)

mysql> select * from t1;              #查看t1表数据内容
+------+-------+
| id | name |
+------+-------+
| 1 | hello |
+------+-------+
1 row in set (0.00 sec)

mysql> select * from t1 where id=1 and name='hello';    #id、name多个条件查询
+------+-------+
| id | name |
+------+-------+
| 1 | hello |
+------+-------+
1 row in set (0.00 sec)

mysql> desc t1;                  #查看t1表字段内容
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | varchar(20) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> flush privileges;              #刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql> delete from t1;              #清空表内容
Query OK, 1 row affected (0.09 sec)

mysql> desc t1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | varchar(20) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> select * from t1;
Empty set (0.00 sec)

mysql> drop table t1;            #删除表
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> drop database mysql;        #删除mysql数据库

Query OK, 0 rows affected (0.00 sec)

mysql> exit                #退出数据库
Bye

[root@b ~]#mysqldump -uroot -pxxxxxxxx  lisi> lisi.sql        #备份lisi数据库为lisi.sql

猜你喜欢

转载自www.cnblogs.com/xiaofeng666/p/10919213.html