打开Mysql
'''
source ~/.bash_profile
mysql -u root -p
'''
运行结果:
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;
'''
运行结果:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
选择需要操作的库,打开库
'''
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
查看当前库中的数据表
'''
show tables;
'''
运行结果:
+---------------------------+
| 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)
查看标中的数据
'''
select * from user; #查看所有数据
select host, user from user;
'''
运行结果:
mysql> select host, user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
创建库
'''
create database 库名 default chartset=utf8;
'''
创建表
'''
create table 表名(
字段名 类型 字段约束,
字段名 类型 字段约束,
字段名 类型 字段约束,
)engine == innodb default charset=utf8;
'''
添加数据
'''
insert into user(name, age,sex) values('admin',26,'男')
'''