Mysql 基本操作

打開Mysql

'''
source ~/.bash_profile
mysql -u root -p
'''
運(yùn)行結(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;
'''
運(yùn)行結(jié)果:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)

選擇需要操作的庫,打開庫

'''
use mysql;
'''
運(yùn)行結(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;
'''
運(yùn)行結(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;
'''
運(yùn)行結(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,'男')
'''

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容