当前位置:网站首页>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
边栏推荐
- RT-1052学习笔记 - GPIO架构分析
- Introduction to intrusion detection data set
- 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
- go struct
- Leetcode 1346. Check whether integers and their multiples exist
- [PTA] l1-006 continuity factor
- 缓存淘汰算法初步认识(LRU和LFU)
- Case of the third day of go language development fresh every day project - news release system II
- Leetcode 20. Valid parentheses
- How can matlab obtain the truncated image in trainingimagelabeler
猜你喜欢
Summary and effect analysis of methods for calculating binocular parallax
[SQL] string series 2: split a string into multiple lines according to specific characters
Unity solves Z-fighting
LeetCode 994、腐烂的橘子
2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
How to use PM2 management application? Come in and see
Come in and teach you how to solve the problem of port occupation
[latex] 5 how to quickly write out the latex formula corresponding to the formula
A login and exit component based on token
随机推荐
ArcGIS js api 4. X submergence analysis and water submergence analysis
三十一. `prototype`显示原型属性和`__proto__`隐式原型属性
Tensorflow 2 basic operation dictionary
Resolve the eslint warning -- ignore the warning that there is no space between the method name and ()
Cmake project under vs2019: calculating binocular parallax using elas method
LeetCode 1346、检查整数及其两倍数是否存在
How to configure SSH public key in code cloud
黑客的入侵方式你知道几种?
LeetCode 20、有效的括号
Easy to use nprogress progress bar
Leetcode 1351. Negative numbers in statistical ordered matrices
LeetCode 116. Populate the next right node pointer for each node
Solution: NPM err! code ELIFECYCLE npm ERR! errno 1
三十.什么是vm和vc?
Unity asset import settings
C migration project record: modify namespace and folder name
Recognition of high-speed road signs by Matlab using alexnet
Vscode download speed up
vulnhub DC:1渗透笔记
【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行