当前位置:网站首页>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

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071036123160.html