mysql基本操作(一)
1、登录mysql
mysql -h localhost -u root -p 登录mysql,其中 -h是指定要连接mysql服务器的主机名 -u是指定用户 -次数登录必须用-p输入密码,如果不输入密码可以使用
mysql -h localhost -u root -p123456 注意-p后面没有空格,紧跟密码。
[root@master ~]# mysql -h localhost -u root -p123456
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 114
Server version: 5.7.21 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
2、查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
4 rows in set (0.00 sec)
mysql>
3、创建数据库
mysql> create database test;
Query OK, 1 row affected (0.12 sec)
mysql>
4、选中数据库
mysql> use test
Database changed
5、查看数据库表
mysql> show tables;
Empty set (0.00 sec)
6、删除一个数据名称为test;
mysql> drop database test;
Query OK, 0 rows affected (0.61 sec)
7、创建一个class的表和score表(要先选中数据库use test)
mysql> create table class ( stu int, name varchar(20), age int, area varchar(20) );
Query OK, 0 rows affected (0.84 sec)
mysql> create table score(
-> stu int,
-> name varchar(20),
-> ke varchar(10),
-> fen int
-> );
Query OK, 0 rows affected (0.07 sec)
8、修改表名score为newscore
mysql> rename table score to newscore;
Query OK, 0 rows affected (0.15 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| class |
| newscore |
+----------------+
2 rows in set (0.00 sec)
9、删除表名newscore
drop table newscore;
10、查看表结构
mysql> desc class;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| stu | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| area | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
4 rows in set (0.02 sec)