Linux连接Mysql数据库命令

一、Mysql数据库相关操作


# 登录本地Mysql数据库

[root@mysql ~]# mysql -u【用户名】 -p

-------------------------------------------------------------------------

# 登录rds Mysql数据库

[root@mysql ~]# mysql -h【连接地址】 -P【端口:非必须】 -u【用户名】 -p -D【数据库名称:非必须】

-------------------------------------------------------------------------

# 将数据库导出成sql文件

[root@mysql ~]# mysqldump -u【用户名】 -p export【导出的数据库名称】 > new_export.sql【导出成指定名称的sql文件】

-------------------------------------------------------------------------

# 执行sql文件,导入数据

[root@mysql ~]# mysql -u【用户名】 -p
mysql> use new_export;
mysql> source new_export.sql;【在当前sql所在目录登录数据库,否则要指定sql据对路径】
mysql> exit;
[root@mysql ~]# ls
new_export.sql

二、Redis相关操作


# 连接本地redis

[root@redis ~]# redis-cli
127.0.0.1:6379> 

-------------------------------------------------------------------------

# 连接rds redis

[root@redis ~]# redis-cli -h【连接地址】

-------------------------------------------------------------------------

# Redis连接到redis服务,用户输入redis链接密码,若没设置密码,则不需要此步骤

[root@redis ~]# redis-cli
127.0.0.1:6379> AUTH 密码

-------------------------------------------------------------------------

# Redis查看当前数据库的 key 的数量

[root@redis ~]# redis-cli
127.0.0.1:6379> AUTH 密码
127.0.0.1:6379> DBSIZE
(integer) 0

-------------------------------------------------------------------------

#  Redis切库,切换到指定的数据库,数据库索引号 index 用数字值指定

[root@redis ~]# redis-cli
127.0.0.1:6379> AUTH 密码
127.0.0.1:6379> DBSIZE
(integer) 0
127.0.0.1:6379> SELECT 12 
OK

-------------------------------------------------------------------------

# Redis删除当前库的keys

[root@redis ~]# redis-cli
127.0.0.1:6379> AUTH 密码
127.0.0.1:6379> DBSIZE
(integer) 0
127.0.0.1:6379> SELECT 12 
OK
127.0.0.1:6379> FLUSH
OK

-------------------------------------------------------------------------

# Redis删除所有的keys

[root@redis ~]# redis-cli
127.0.0.1:6379> AUTH 密码
127.0.0.1:6379> DBSIZE
(integer) 0
127.0.0.1:6379> SELECT 12 
OK
127.0.0.1:6379> FLUSHALL
OK

Guess you like

Origin blog.csdn.net/qq_37604998/article/details/118575380