当前位置:网站首页>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
边栏推荐
- Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
- SQL: query duplicate data and delete duplicate data
- Plato Farm元宇宙IEO上线四大,链上交易颇高
- 16MySQL之DCL 中 COMMIT和ROllBACK
- Leetcode 1337. Row K with the weakest combat effectiveness in the matrix
- The ODB model calculates the data and outputs it to excel
- bounding box iou
- LeetCode 1351、统计有序矩阵中的负数
- 缓存淘汰算法初步认识(LRU和LFU)
- Awk print special characters
猜你喜欢
Unity solves Z-fighting
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
Syntax Error: TypeError: this. getOptions is not a function
LeetCode 994、腐烂的橘子
Devexpress 14.1 installation record
Matlab matrix index problem
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
Linux64Bit下安装MySQL5.6-不能修改root密码
Matlab analytic hierarchy process to quickly calculate the weight
Matlab: psychtoolbox installation
随机推荐
Some basic configurations in interlij idea
DOS command of Intranet penetration
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
bounding box iou
6-5 字符串 - 2. 字符串复制(赋值) (10 分)C语言标准函数库中包括 strcpy 函数,用于字符串复制(赋值)。作为练习,我们自己编写一个功能与之相同的函数。
Communication between RING3 and ring0
Matlab: psychtoolbox installation
go slice
Plato Farm元宇宙IEO上线四大,链上交易颇高
Development of Matlab GUI bridge auxiliary Designer (functional introduction)
GO語言開發天天生鮮項目第三天 案例-新聞發布系統二
Leetcode 709, convert to lowercase
LeetCode 542、01 矩阵
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
Commit and ROLLBACK in DCL of 16mysql
Flex layout
上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
Commit and rollback in DCL of 16 MySQL
[latex] 5 how to quickly write out the latex formula corresponding to the formula
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二