当前位置:网站首页>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
边栏推荐
猜你喜欢
What is an esp/msr partition and how to create an esp/msr partition
【统计学习方法】学习笔记——支持向量机(下)
SQL Lab (46~53) (continuous update later) order by injection
BGP actual network configuration
Vxlan 静态集中网关
Multi row and multi column flex layout
Zhimei creative website exercise
ICLR 2022 | pre training language model based on anti self attention mechanism
Sorting, dichotomy
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
随机推荐
Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)
Pule frog small 5D movie equipment | 5D movie dynamic movie experience hall | VR scenic area cinema equipment
Design and implementation of communication protocol
【PyTorch实战】用RNN写诗
leetcode刷题:二叉树24(二叉树的最近公共祖先)
2022-07-07 Daily: Ian Goodfellow, the inventor of Gan, officially joined deepmind
HZOJ #235. 递归实现指数型枚举
Simple implementation of call, bind and apply
2022a special equipment related management (boiler, pressure vessel and pressure pipeline) simulated examination question bank simulated examination platform operation
Importance of database security
[learn micro services from 0] [02] move from single application to service
[statistical learning method] learning notes - logistic regression and maximum entropy model
Object. Simple implementation of assign()
用mysql查询某字段是否有索引
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Leetcode brush questions: binary tree 19 (merge binary tree)
Airserver automatically receives multi screen projection or cross device projection
Minimalist movie website
Realize a simple version of array by yourself from
NPM instal reports agent or network problems