当前位置:网站首页>Linux中,MySQL的常用命令
Linux中,MySQL的常用命令
2022-04-23 20:39:00 【小简(JanYork)】
登录
mysql -u用户名 -p
-- 然后在下面输入密码,Linux的密码不会显示出,盲打就可以
mysql -u用户名 -p密码
-- 这种方式将直接登录
开关
开启数据库
service mysql start
我这里没加分号,要是终端运行命令,记得结尾加上;
不然就可能出现如下结果。
关闭数据库
service mysql stop
重启数据库
service mysql restart
常用操作
显示数据库列表
show databases;
创建、删除数据库
create database 数据库名;
drop database 数据库名;
显示库中的数据表
use mysql;
show tables;
显示数据表结构
describe 数据表名;
修改密码
SET PASSWORD命令(需登录)
mysql> set password for 用户名@localhost = password('新密码');
使用sql语句更新 mysql 库中的 user 表(需登录)
mysql> use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql> flush privileges;
mysqladmin命令,明文(不需登录)
mysqladmin -u用户名 -p旧密码 password 新密码
命令,密文(不需登录)
mysqladmin -u用户名 -p旧密码 password+回车,然后输入两次新密码
其他命令
导入、导出数据库(不需登录)
导出所有数据库
mysqldump -u用户名 -p密码 --all-databases >导出路径
导出指定数据库
mysqldump -u用户名 -p密码 --databases 数据库名>导出路径
导出指定数据库的结构(无数据)
语法:mysqldump -u用户名 -p密码 --no-data --databases 数据库名>导出路径
举例:mysqldump -uroot -p123456 --no-data --databases testdatebase >/tmp/testdatebase_no_data.sql
导出指定数据库中的指定表
语法:mysqldump -u用户名 -p密码 --databases 数据库名 --tables 数据表名>导出路径
举例:mysqldump -uroot -p123456 --databases testdatebase --tables t_user >/tmp/testdatebase_user.sql
导出指定数据库中的指定表的结构(无数据)
语法:mysqldump -u用户名 -p密码 --no-data --databases 数据库名 --tables 数据表名>导出路径
举例:mysqldump -uroot -p123456 --no-data --databases testdatebase --tables t_user >/tmp/testdatebase_user_no_data.sql
导出指定数据库中的指定表,设置查询条件
语法:mysqldump -u用户名 -p密码 --databases 数据库名 --tables 数据表名 --where='条件'>导出路径
举例:mysqldump -uroot -p123456 --databases testdatebase --tables t_user --where='user_no=1'>/tmp/mysql_user_no.sql
跨服务器备份数据库
-- 将 host1 服务器中的 db1 数据库的所有数据导入到 host2 中的db2数据库中,db2的数据库必须存在否则会报错
-- (经测试,在mysql5.5版本中,db2存在即可,实际生成数据库名称与db1一致;加上-C参数可以启用压缩传递)
语法:mysqldump --host=host1 -u用户名 -p密码 --databases db1 |mysql --host=host2 -u用户名 -p密码 --databases db2
举例:mysqldump --host=192.168.1.101 -uroot -p123456 -C --databases testdatebase |mysql --host=192.168.3.102 -uroot -p123456 --database testdatebase
通过 sql 文件导入数据库
语法:mysql -u用户名 -p密码 < 导入路径
举例:mysql -uroot -p123456 < /tmp/testdatebase.sql
注:部分摘自博客园
版权声明
本文为[小简(JanYork)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_60750453/article/details/124305048
边栏推荐
- Unity solves Z-fighting
- Analysis of the relationship between generalized Bim and CAD under the current background
- Matlab analytic hierarchy process to quickly calculate the weight
- How do BIM swindlers cheat? (turn)
- Rt-1052 learning notes - GPIO architecture analysis
- LeetCode 1351、统计有序矩阵中的负数
- 16MySQL之DCL 中 COMMIT和ROllBACK
- Some basic configurations in interlij idea
- MySQL 存储过程和函数
- Scrapy教程 - (2)寫一個簡單爬蟲
猜你喜欢
go slice
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
LeetCode 74、搜索二维矩阵
Case of the third day of go language development fresh every day project - news release system II
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Recommend an open source free drawing software draw IO exportable vector graph
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
Unity solves Z-fighting
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
[matlab 2016 use mex command to find editor visual studio 2019]
随机推荐
BMP JPEG 图片转换为矢量图像 ContourTrace
[PTA] l1-006 continuity factor
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细
Leetcode 709, convert to lowercase
Leetcode 74. Search two-dimensional matrix
16MySQL之DCL 中 COMMIT和ROllBACK
Bash script learning -- for loop traversal
2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
On BIM data redundancy theory
三十一. `prototype`显示原型属性和`__proto__`隐式原型属性
How to use PM2 management application? Come in and see
Unity asset import settings
[PTA] l2-011 play with binary tree
I JS deep copy and shallow copy
Matlab matrix index problem
【PTA】L2-011 玩转二叉树
Scripy tutorial - (2) write a simple crawler
Elastic box model
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
缓存淘汰算法初步认识(LRU和LFU)