-
安装
安装mysql:$ sudo apt-get install -y mysql-server
-
启动
启动mysql: sudo service mysql start
关闭mysql:sudo service mysql stop
重启mysql: sudo service mysql restart
-
使用
进入mysql: mysql -u 用户名 -p
然后会要求输入密码,则输入用户名对应的密码即可进入mysql
创建数据库:create database student_db;
删除数据库:drop database student_db;
进入数据库:use database_name;
创建表: create table table_name (字段参数);
or create table if not exists table_name (字段参数);
删除表:drop table table_name;
or drop table if exists table_name;
查看表结构:desc table_name;
or show columns from table_name;
or describe table_name;
查看表数据:select * from table_name;
查看n到m行:select * from table_name limit n-1,m
插入数据:insert into table_name(col1, col2) value(v1,v2);
修改数据:update table_name set col1=v1 where 表达式
退出当前数据库:quit;
退出mysql: quit;
ubuntu@VM-0-12-ubuntu:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)
Copyright (c) 2000, 2019, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school_db |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>use temp_db;
mysql>CREATE TABLE Persons (
-> PersonID int,
-> LastName varchar(255),
-> FirstName varchar(255),
-> Address varchar(255),
-> City varchar(255)
-> );
Query OK, 0 rows affected (0.04 sec)
mysql> show tables;
+-------------------+
| Tables_in_temp_db |
+-------------------+
| Persons |
+-------------------+
1 row in set (0.00 sec)
mysql>
网友评论