MySQL----MySQL数据库常用的操作命令
作者:redrose2100   类别:    日期:2022-05-05 03:16:40    阅读:1137 次   消耗积分:0 分

1、数据库的常用操作

  • 登录mysql数据库
  1. mysql -uroot -p
  2. # 然后输入密码:

如:

  1. root@a8226422817e:/# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 1094
  5. Server version: 5.7.36 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql>
  • 退出数据库
  1. exit;
  • 查看有哪些数据库:
  1. show databases;

如:

  1. mysql> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | blog_redrose2100 |
  7. | mysql |
  8. | performance_schema |
  9. | sys |
  10. +--------------------+
  11. 5 rows in set (0.01 sec)
  12. mysql>
  • 查看数据库的当前时间
  1. select now();

如:

  1. mysql> select now();
  2. +---------------------+
  3. | now() |
  4. +---------------------+
  5. | 2022-05-05 03:08:39 |
  6. +---------------------+
  7. 1 row in set (0.00 sec)
  8. mysql>
  • 查看当前数据安装软件的版本
  1. select version();

如:

  1. mysql> select version();
  2. +-----------+
  3. | version() |
  4. +-----------+
  5. | 5.7.36 |
  6. +-----------+
  7. 1 row in set (0.00 sec)
  8. mysql>
  • 创建数据库
  1. create database 数据库名 charset=utf8;

如:

  1. mysql> create database demo charset=utf8;
  2. Query OK, 1 row affected (0.01 sec)
  3. mysql> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | blog_redrose2100 |
  9. | demo |
  10. | mysql |
  11. | performance_schema |
  12. | sys |
  13. +--------------------+
  14. 6 rows in set (0.00 sec)
  15. mysql>
  • 删除数据库
  1. drop database 数据库名;

如:

  1. mysql> drop database demo;
  2. Query OK, 0 rows affected (0.00 sec)
  3. mysql> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | blog_redrose2100 |
  9. | mysql |
  10. | performance_schema |
  11. | sys |
  12. +--------------------+
  13. 5 rows in set (0.00 sec)
  14. mysql>
  • 查看当前的数据库
  1. select database();

如:

  1. mysql> select database();
  2. +------------+
  3. | database() |
  4. +------------+
  5. | NULL |
  6. +------------+
  7. 1 row in set (0.00 sec)
  8. mysql>
  • 使用数据库
  1. use 数据库名;

如:

  1. mysql> use blog_redrose2100;
  2. Reading table information for completion of table and column names
  3. You can turn off this feature to get a quicker startup with -A
  4. Database changed
  5. mysql> select database();
  6. +------------------+
  7. | database() |
  8. +------------------+
  9. | blog_redrose2100 |
  10. +------------------+
  11. 1 row in set (0.00 sec)
  12. mysql>
始终坚持开源开放共享精神,同时感谢您的充电鼓励和支持!
版权所有,转载本站文章请注明出处:redrose2100, http://blog.redrose2100.com/article/89
个人成就
  • 博客总数: 613 
  • 阅读总量: 712344 
  • 2022年 : 371 篇 
  • 2023年 : 211 篇 
  • 2024年 : 31 篇 
  • 2025年 : 0 篇 
测试开发技术全栈公众号
DevOps技术交流微信群