linux下终端操作mysql数据库

news/2024/11/23 5:37:15/

目录

一.检查mysql是否安装

1.  查看文件安装路径

2.  查询运行文件所在路径(文件夹地址)

二.登录mysql

三.列出mysql全部用户

四.常用指令

1.查看全部数据库

 2.选择数据库

3.查看该数据库的全部数据表

4.显示表结构

5.运行sql文件

6.显示数据库概况

五.查看帮助指令

一.检查mysql是否安装

1.  查看文件安装路径

# gr @ gr-System-Product-Name in ~ [10:05:21] 
$ whereis mysql
mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/man/man1/mysql.1.gz

2.  查询运行文件所在路径(文件夹地址)

# gr @ gr-System-Product-Name in ~ [10:05:26] 
$ which mysql     
/usr/bin/mysql

二.登录mysql

# gr @ gr-System-Product-Name in ~ [10:36:49] 
$ mysql -u用户名 -p密码
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 55
Server version: 8.0.32 MySQL Community Server - GPLCopyright (c) 2000, 2023, Oracle and/or its affiliates.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> 

三.列出mysql全部用户

必须要用root账户登录,进入mysql环境

# gr @ gr-System-Product-Name in ~ [10:39:50] 
$ mysql -uroot -p密码
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56
Server version: 8.0.32 MySQL Community Server - GPLCopyright (c) 2000, 2023, Oracle and/or its affiliates.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> 
mysql> SELECT User, Host FROM mysql.user;
+------------------+-----------+
| User             | Host      |
+------------------+-----------+
| ga               | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

四.常用指令

1.查看全部数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| test               |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
6 rows in set (0.02 sec)

 2.选择数据库

mysql> use mysql;
Database changed

3.查看该数据库的全部数据表

mysql> show tables;
+------------------------------------------------------+
| Tables_in_mysql                                      |
+------------------------------------------------------+
| columns_priv                                         |
| component                                            |
| db                                                   |
| default_roles                                        |
| engine_cost                                          |
| func                                                 |
| general_log                                          |
| global_grants                                        |
| user                                                 |
+------------------------------------------------------+
38 rows in set (0.00 sec)

4.显示表结构

mysql> desc user;

5.运行sql文件

mysql> use mysql
Database changed
mysql> source /user/test.sql

6.显示数据库概况

  当前使用的数据库,当前用户,mysql版本信息

mysql> status
--------------
mysql  Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)Connection id:		59
Current database:	mysql
Current user:		root@localhost
SSL:			Not in use
Current pager:		less
Using outfile:		''
Using delimiter:	;
Server version:		8.0.32 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			5 days 2 min 4 secThreads: 4  Questions: 2198  Slow queries: 0  Opens: 580  Flush tables: 3  Open tables: 499  Queries per second avg: 0.005
--------------

五.查看帮助指令

mysql> \?For information about MySQL products and services, visit:http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:https://shop.mysql.com/List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.
ssl_session_data_print Serializes the current SSL session data to stdout or fileFor server side help, type 'help contents'

六.权限问题

1.查询某用户的权限

mysql> show grants for 'ga'@'%';
+---------------------------------------------------+
| Grants for gauture@%                              |
+---------------------------------------------------+
| GRANT USAGE ON *.* TO `ga`@`%`                    |
| GRANT ALL PRIVILEGES ON `table01`.* TO `ga`@`%`   |
| GRANT ALL PRIVILEGES ON `table01`.* TO `ga`@`%`   |
+---------------------------------------------------+
3 rows in set (0.00 sec)

2.给用户添加权限

mysql> GRANT ALL PRIVILEGES ON test.* TO 'ga'@'%';
Query OK, 0 rows affected (0.01 sec)

七.退出

mysql> exit
Bye


http://www.ppmy.cn/news/28832.html

相关文章

离散数学---期末复习知识点

一、 数理逻辑 [复习知识点] 1、命题与联结词(否定¬、析取∨、合取∧、蕴涵→、等价↔),命题(非真既假的陈述句),复合命题(由简单命题通过联结词联结而成的命题) 2、命题公式与赋值(成真、成假)&#x…

【Android源码面试宝典】MMKV从使用到原理分析(一)

去年,我们写过一篇文章,对于android原生提供的key-value存储API SharePreference,进行了从使用到原理的深入分析,同时对其中存在的ANR问题、存取慢等问题,进行了深入的探索、总结。但是之前的文章,我们仅仅指出了问题,没有给大家提供解决方案,也就是说,SharePreferenc…

一个线程两次调用start()方法会出现什么情况?

第17讲 | 一个线程两次调用start()方法会出现什么情况? 今天我们来深入聊聊线程,相信大家对于线程这个概念都不陌生,它是 Java 并发的基础元素,理解、操纵、诊断线程是 Java 工程师的必修课,但是你真的掌握线程了吗&am…

spring boot 配合element ui vue实现表格的批量删除(前后端详细教学,简单易懂,有手就行)

目录 一.前言: 二. 前端代码: 2.1.element ui组件代码 2.2删除按钮 2.3.data 2.4.methods 三.后端代码: 一.前言: 研究了其他人的博客,找到了一篇有含金量的,进行了部分改写实现前后端分离&#xff0…

Learining C++ No.12【vector】

引言: 北京时间:2023/2/27/11:42,高数考试还在进行中,我充分意识到了学校的不高级,因为题目真的没什么意思,虽然挺平易近人,但是……,考试期间时间比较放松,所以不能耽误…

【算法】【数组与矩阵模块】求数组中需要排序的最短子数组长度

目录前言问题介绍解决方案代码编写java语言版本c语言版本c语言版本思考感悟写在最后前言 当前所有算法都使用测试用例运行过,但是不保证100%的测试用例,如果存在问题务必联系批评指正~ 在此感谢左大神让我对算法有了新的感悟认识! 问题介绍 …

攻不下dfs不参加比赛(七)

标题 为什么练dfs题目总结重点为什么练dfs 相信学过数据结构的朋友都知道dfs(深度优先搜索)是里面相当重要的一种搜索算法,可能直接说大家感受不到有条件的大家可以去看看一些算法比赛。这些比赛中每一届或多或少都会牵扯到dfs,可能提到dfs大家都知道但是我们为了避免眼高手…

飞行机器人专栏(十)-- 异构多视角视觉系统

感知系统架构为满足天空端主控制器的诸如RGB-D图像处理等大容量数据吞吐、高速并行计算、实时运动控制以及通信和可视化任务的计算算力需求,同时优化功耗表现,采用了结构紧凑、功耗表现优异的边缘计算硬件NVIDA IJetson AGXOrin 。该开发者套件包含高性能…