sql基本语句

1、mysql_secure_installation 设置数据库密码

2、mysql -u root -p password -h 127.0.0.1;
以root账号,本地ip 127.0.0.1登录数据库

3、show databases;
查看数据库

4、use luodb;
进入数据库luodb

5、desc table1;
列出table1

6、select * from table1;
列出table1所有信息。

7、help 查看帮助


1、登录数据库:

[root@Centos7 ~]#mysql -uroot -p666666 -h 127.0.0.1
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 99
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

2、查看数据库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| blogdb             |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)
#有5个数据库

3、进入"mysql"这个数据库

MariaDB [(none)]> use 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

4、列出当前数据库的表格

MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| time_zone_transition_type |
| user                      |
...部分省略
+---------------------------+
24 rows in set (0.00 sec)
#列出当前数据库的表格,可以看到有24个表格

5、查看user这个表格的结构

MariaDB [mysql]> desc user
    -> ;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field                  | Type                              | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host                   | char(60)                          | NO   | PRI |         |       |
| User                   | char(16)                          | NO   | PRI |         |       |
| Password               | char(41)                          | NO   |     |         |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Insert_priv            | enum('N','Y')                     | NO   |     | N       |       |
| Update_priv            | enum('N','Y')                     | NO   |     | N       |       |

...部分省略

42 rows in set (0.00 sec)

6、列出表格”user“的host、user、password三个字段的信息。

MariaDB [mysql]> select host,name,password from user;
ERROR 1054 (42S22): Unknown column 'name' in 'field list'
MariaDB [mysql]> select host,user,password from user;
+-----------------+--------+-------------------------------------------+
| host            | user   | password                                  |
+-----------------+--------+-------------------------------------------+
| localhost       | root   | *B2B366CA5C4697F31D4C55D61F0B17E70E5664EC |
| centos7.luo.com | root   | *B2B366CA5C4697F31D4C55D61F0B17E70E5664EC |
| 127.0.0.1       | root   | *B2B366CA5C4697F31D4C55D61F0B17E70E5664EC |
| ::1             | root   | *B2B366CA5C4697F31D4C55D61F0B17E70E5664EC |
| 127.0.0.1       | wpuser | *B2B366CA5C4697F31D4C55D61F0B17E70E5664EC |
+-----------------+--------+-------------------------------------------+
5 rows in set (0.00 sec)

7、help

MariaDB [mysql]> help

你可能感兴趣的:(sql基本语句)