当前位置:网站首页>MySQL导入SQL文件及常用命令
MySQL导入SQL文件及常用命令
2022-07-07 10:37:00 【全栈程序员站长】
在MySQL Qurey Brower中直接导入*.sql脚本,是不能一次执行多条sql命令的,在mysql中执行sql文件的命令:
mysql> source d:/myprogram/database/db.sql;
另附mysql常用命令:
一) 连接MYSQL:
格式: mysql -h主机地址 -u用户名 -p用户密码
1、例1:连接到本机上的MYSQL
首先在打开DOS窗口,然后进入mysql安装目录下的bin目录下,例如: D:/mysql/bin,再键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>
2、例2:连接到远程主机上的MYSQL (远程:IP地址)
假设远程主机的IP为:10.0.0.1,用户名为root,密码为123。则键入以下命令:
mysql -h10.0.0.1 -uroot -p123
(注:u与root可以不用加空格,其它也一样)
3、退出MYSQL命令
exit (回车)
(二) 修改密码:
格式:mysqladmin -u用户名 -p旧密码 password 新密码
1、例1:给root加个密码123。首先在DOS下进入目录C:/mysql/bin,然后键入以下命令:
mysqladmin -uroot -password 123
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
2、例2:再将root的密码改为456
mysqladmin -uroot -pab12 password 456
(三) 增加新用户:(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”
例1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MYSQL,然后键入以下命令: grant select,insert,update,delete on *.* to [email protected] identified by “abc”;
如果你不想test2有密码,可以再打一个命令将密码消掉。 grant select,insert,update,delete on mydb.* to [email protected] identified by “”;
(四) 显示命令
1、显示数据库列表:
show databases; 刚开始时才两个数据库:mysql和test。mysql库很重要它里面有MYSQL的系统信息,我们改密码和新增用户,实际上就是用这个库进行操作。
2、显示库中的数据表:
use mysql; //打开库 show tables;
3、显示数据表的结构:
describe 表名;
4、建库:
create database 库名;
5、建表:
use 库名; create table 表名 (字段设定列表);
6、删库和删表:
drop database 库名; drop table 表名;
7、将表中记录清空:
delete from 表名;
8、显示表中的记录:
select * from 表名;
导出sql脚本
mysqldump -u 用户名 -p 数据库名 > 存放位置
mysqldump -u root -p test > c:/a.sql
导入sql脚本
mysql -u 用户名 -p 数据库名 < 存放位置
mysqljump -u root -p test < c:/a.sql
注意,test数据库必须已经存在
MySQL导出导入命令的用例
1.导出整个数据库
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名表名> 导出的文件名
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3.导出一个数据库结构
mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql
-d 没有数据 –add-drop-table 在每个create语句之前增加一个drop table
4.导入数据库
常用source 命令
进入mysql数据库控制台,
如mysql -u root -p
mysql>use 数据库
然后使用source命令,后面参数为脚本文件(如这里用到的.sql)
mysql>source d:wcnc_db.sql 亲测可行
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113468.html原文链接:https://javaforall.cn
边栏推荐
- 2022危险化学品生产单位安全生产管理人员考题及在线模拟考试
- Guangzhou held work safety conference
- 【从 0 开始学微服务】【03】初探微服务架构
- 密码学系列之:在线证书状态协议OCSP详解
- SQL head injection -- injection principle and essence
- [statistical learning methods] learning notes - Chapter 4: naive Bayesian method
- The left-hand side of an assignment expression may not be an optional property access.ts(2779)
- 【从 0 开始学微服务】【00】课程概述
- [statistical learning method] learning notes - logistic regression and maximum entropy model
- Utiliser la pile pour convertir le binaire en décimal
猜你喜欢

2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作

解密GD32 MCU产品家族,开发板该怎么选?

HZOJ #240. 图形打印四

SQL lab 11~20 summary (subsequent continuous update) contains the solution that Firefox can't catch local packages after 18 levels

MPLS experiment

Airserver automatically receives multi screen projection or cross device projection

leetcode刷题:二叉树23(二叉搜索树中的众数)

How to apply @transactional transaction annotation to perfection?

SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)

ps链接图层的使用方法和快捷键,ps图层链接怎么做的
随机推荐
The left-hand side of an assignment expression may not be an optional property access. ts(2779)
What is an esp/msr partition and how to create an esp/msr partition
Simple implementation of call, bind and apply
About web content security policy directive some test cases specified through meta elements
Vxlan 静态集中网关
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
【从 0 开始学微服务】【03】初探微服务架构
[pytorch practice] image description -- let neural network read pictures and tell stories
Day-19 IO stream
广州市召开安全生产工作会议
Several ways to clear floating
Vxlan static centralized gateway
leetcode刷题:二叉树24(二叉树的最近公共祖先)
[爬虫]使用selenium时,躲避脚本检测
【PyTorch实战】图像描述——让神经网络看图讲故事
[statistical learning method] learning notes - logistic regression and maximum entropy model
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
HZOJ #240. 图形打印四
AirServer自动接收多画面投屏或者跨设备投屏