当前位置:网站首页>MySQL importing SQL files and common commands
MySQL importing SQL files and common commands
2022-07-07 12:49:00 【Full stack programmer webmaster】
stay MySQL Qurey Brower Directly import *.sql Script , You can't execute more than one at a time sql Ordered , stay mysql In the implementation of sql The order of the document :
mysql> source d:/myprogram/database/db.sql;
Attached separately mysql Common commands :
One ) Connect MYSQL:
Format : mysql -h The host address -u user name -p User password
1、 example 1: Connected to the MYSQL
First on DOS window , Then enter mysql Install under directory bin Under the table of contents , for example : D:/mysql/bin, Type the command again mysql -uroot -p, I'll prompt you to enter the password , If just installed MYSQL, The super user root There is no password , Therefore, you can directly enter MYSQL It's in ,MYSQL The prompt for is :mysql>
2、 example 2: Connect to... On the remote host MYSQL ( long-range :IP Address )
Suppose the remote host's IP by :10.0.0.1, The user is called root, The password for 123. Then type the following command :
mysql -h10.0.0.1 -uroot -p123
( notes :u And root You don't need to add space , So are the others )
3、 sign out MYSQL command
exit ( enter )
( Two ) Change Password :
Format :mysqladmin -u user name -p Old password password New password
1、 example 1: to root Add a code 123. First, in the DOS Go down to the directory C:/mysql/bin, Then type the following command :
mysqladmin -uroot -password 123
notes : Because at the beginning root No password , therefore -p The old password can be omitted .
2、 example 2: then root The password of is changed to 456
mysqladmin -uroot -pab12 password 456
( 3、 ... and ) Add new users :( Be careful : Different from the above , The next reason is MYSQL Commands in the environment , So it's followed by a semicolon as the command Terminator )
Format :grant select on database .* to user name @ Log on to the host identified by “ password ”
example 1、 Add a user test1 The password for abc, Let him log on to any host , And query all databases 、 Insert 、 modify 、 Delete permissions . First of all, it is used to root User connection MYSQL, Then type the following command : grant select,insert,update,delete on *.* to [email protected] identified by “abc”;
If you don't want to test2 Password , You can type another command to erase the password . grant select,insert,update,delete on mydb.* to [email protected] identified by “”;
( Four ) Show command
1、 Show database list :
show databases; It started with two databases :mysql and test.mysql Library is very important. It has MYSQL System information , We change the password and add new users , In fact, this library is used for operation .
2、 Display the data table in the library :
use mysql; // Open the library show tables;
3、 Show the structure of the data table :
describe Table name ;
4、 Building database :
create database Library name ;
5、 Build table :
use Library name ; create table Table name ( Field setting list );
6、 Delete database and table :
drop database Library name ; drop table Table name ;
7、 Empty the records in the table :
delete from Table name ;
8、 Show the records in the table :
select * from Table name ;
export sql Script
mysqldump -u user name -p Database name > Storage location
mysqldump -u root -p test > c:/a.sql
Import sql Script
mysql -u user name -p Database name < Storage location
mysqljump -u root -p test < c:/a.sql
Be careful ,test The database must already exist
MySQL Use case of Export Import command
1. Export the entire database
mysqldump -u user name -p Database name > Exported file name
mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql
2. Export a table
mysqldump -u user name -p Database name, table name > Exported file name
mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql
3. Export a database structure
mysqldump -u wcnc -p -d –add-drop-table smgp_apps_wcnc >d:wcnc_db.sql
-d No data –add-drop-table At every create Add a... Before the statement drop table
4. Import database
Commonly used source command
Get into mysql Database console ,
Such as mysql -u root -p
mysql>use database
And then use source command , The following parameters are script files ( As used here .sql)
mysql>source d:wcnc_db.sql Pro feasible measurement
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113468.html Link to the original text :https://javaforall.cn
边栏推荐
- leetcode刷题:二叉树20(二叉搜索树中的搜索)
- Static vxlan configuration
- Talk about four cluster schemes of redis cache, and their advantages and disadvantages
- 2022 polymerization process test question simulation test question bank and online simulation test
- 【统计学习方法】学习笔记——提升方法
- Session
- 基于NeRF的三维内容生成
- Simple implementation of call, bind and apply
- 详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
- JS to convert array to tree data
猜你喜欢
RHSA first day operation
JS to convert array to tree data
Multi row and multi column flex layout
Master公式。(用于计算递归的时间复杂度。)
2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
BGP actual network configuration
Cookie
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
Aike AI frontier promotion (7.7)
【PyTorch实战】图像描述——让神经网络看图讲故事
随机推荐
leetcode刷题:二叉树20(二叉搜索树中的搜索)
【从 0 开始学微服务】【03】初探微服务架构
How to apply @transactional transaction annotation to perfection?
【统计学习方法】学习笔记——支持向量机(上)
[deep learning] image multi label classification task, Baidu paddleclas
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
Day-14 common APIs
Visual stdio 2017 about the environment configuration of opencv4.1
Day-20 file operation, recursive copy, serialization
Several ways to clear floating
Four functions of opencv
MPLS experiment
【从 0 开始学微服务】【02】从单体应用走向服务化
[pytorch practice] write poetry with RNN
[difficult and miscellaneous]pip running suddenly appears modulenotfounderror: no module named 'pip‘
[statistical learning methods] learning notes - Chapter 4: naive Bayesian method
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备
leetcode刷题:二叉树27(删除二叉搜索树中的节点)
RHSA first day operation
【二叉树】删点成林