打開Mysql
'''
source ~/.bash_profile
mysql -u root -p
'''
運行結(jié)果:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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;
'''
運行結(jié)果:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
選擇需要操作的庫豫喧,打開庫
'''
use mysql;
'''
運行結(jié)果:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
查看當(dāng)前庫中的數(shù)據(jù)表
'''
show tables;
'''
運行結(jié)果:
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| engine_cost |
| event |
| func |
| general_log |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
31 rows in set (0.00 sec)
查看標(biāo)中的數(shù)據(jù)
'''
select * from user; #查看所有數(shù)據(jù)
select host, user from user;
'''
運行結(jié)果:
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
創(chuàng)建庫
'''
create database 庫名 default chartset=utf8;
'''
創(chuàng)建表
'''
create table 表名(
字段名 類型 字段約束筒严,
字段名 類型 字段約束丑念,
字段名 類型 字段約束巴比,
)engine == innodb default charset=utf8;
'''
添加數(shù)據(jù)
'''
insert into user(name, age,sex) values('admin',26,'男')
'''