CMD command Daquan manipulation Mysql

Connection: mysql -h host address -u user name -p User password (Note: u and the root can not have spaces, the other is the same)
off: exit (Enter)

Creating an Authorization: grant select on database * to username @ log on the host identified by \ "password \."
Change Password: mysqladmin -u username -p password old password new password
delete authorization: revoke select, insert, update, delete om * . * fromtest2 @ localhost;

Display Database: show databases;
Display Data Table: show tables;
display list structure: describe table name;

Create a library: create database library name;
delete database: drop database database name;
use the library: use the library name;

Create a table: create table table name (field set list);
delete tables: drop table table name;
modify table: alter table t1 rename t2
lookup table: select * from table name;
empty table: delete from table name;
backup table: mysqlbinmysqldump -h (ip) -uroot -p ( password) databasenametablename> tablename.sql
recovery table: mysqlbinmysql -h (ip) -uroot -p (password) databasenametablename <tablename.sql ( first operation before deleting the original table)

Increase Column: ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT, ADDINDEX (c);
Review column: ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE b cCHAR (20);
delete column: ALTER TABLE t2 DROP COLUMN c;

Back up the database: mysql \ bin \ mysqldump -h ( ip) -uroot -p (password) databasename> database.sql
restore the database: mysql \ bin \ mysql -h ( ip) -uroot -p (password) databasename <database.sql
copy the database: mysql \ bin \ mysqldump --all- databases> all-databases.sql
repair the database: mysqlcheck -A -o -uroot -p54safer

Text Data Import: load data local infile \ "filename \" into table table name;
data import and export: mysql \ bin \ mysqlimport database tables.txt

first one, start and stop mysql service
NET STOP mysql
NET Start mysql

The second measure, landing mysql
syntax is as follows: mysql -u username -p password user
type the command mysql -uroot -p, carriage return after the prompt you to enter a password, enter 12345, and then press Enter to enter in to the mysql, mysql's prompt is:
MySQL>
Note that, if the machine is connected to another, is necessary to add a machine parameter -h IP

The third measure, add new users
format: grant permission on the database * to username @ log on the host identified by "password."
For example, to add a password for the user user1 password1, can be allowed to log in on the unit, a database of all query, insert, modify, delete permissions. First, for the root user connected to the mysql, and then type the following command:
Grant the SELECT, INSERT, Update, ON * * touser1 the Delete @ localhost Identified by "password1";.
If you want the users to log in on any machine mysql, then localhost to "%."
If you do not want to have user1 password, you can resort to a command to remove the password.
grant select, insert, update, delete on mydb * touser1 @ localhost identified by "".;

The fourth one: operation of the database
to log on to mysql, and then run the following command at the mysql prompt, each command ends with a semicolon.
1, display a list of databases.
show databases;
default there are two databases: mysql and test. mysql stood inventory system and mysql user rights information, we change the password and add users, in fact, this library to operate.
2, the display library data tables:
use MySQL;
Show Tables;
. 3, shows the structure of the data table:
DESCRIBE name;
4, database and deletion library:
Create Database library name;
drop Database library name;
5, built table:
use library name;
Create table table name (field list);
drop table name;
6, empty record in the table:
Delete from table name;
7, a record in the table:
SELECT * from table;

Fifth strokes, export and import data
1. export data:
the mysqldump --opt test> mysql.test
about to be exported to a database file mysql.test test database, which is a text file
such as: mysqldump -u root -p123456 --databases dbname> mysql.dbname
is to be exported to a database file dbname mysql.dbname in.
2. Data Import:
the mysqlimport the root -p123456 -u <mysql.dbname.
Do not explain it.
3. The text data into the database:
separated by tab key field data between text data.
the Test use;
the Load the Data local infile "filename" into table table name;
1: Use the SHOW statement to find out what databases currently exist on the server:
MySQL> SHOW DATABASES;
2: 2, create a database MySQLdata
MySQL> the CREATE DATABASE MySQLdata;
3: select the database you created
mysql> USE MYSQLDATA; (explain the success of the operation when you press the Enter key database changed appearance!)
4: What table view now exist in the database
MySQL> SHOW tABLES;
5: create a database table
MySQL> the CREATE TABLE MYTABLE (name VARCHAR (20 is), sexCHAR (. 1));
. 6: shows the structure of the table:
MySQL> the DESCRIBE MYTABLE;
. 7: To table added record
mysql> insert into MYTABLE values ( " hyq", "M ");
8: text mode the data into the database tables (e.g. D: /mysql.txt)
MySQL> the LOCAL INFILE the lOAD the dATA 'D: /mysql.txt" INTOTABLE MYTABLE;
. 9: import .sql file commands (e.g. D: /mysql.sql)
mysql> use Database;
mysql> D Source: /mysql.sql;
10: delete table
mysql> tABLE drop MYTABLE;
. 11: empty table
mysql> delete from MYTABLE;
12 is: updating the table data
mysql> update MYTABLE set sex = "f" where name = 'hyq'; 13: backup database mysqldump -u root library name> xxx.data14:

Example 2: connect to the remote host MYSQL
  assumed to remote host IP: 110.110.110.110, the user name is root, password abcd123. Type the following command:   

  mysql-h110.110.110.110 -uroot -pabcd123   

  (Note: u and the root can not have spaces, the other is the same)   

  3, exit MYSQL command: exit

(A) connecting MYSQL:
   Format: -H host address mysql -u username -p user password

1, Example 1: the machine is connected to the MYSQL
  first open DOS window, and then go to the bin directory under the directory mysql installation, For example: D: \ mysql \ bin, then type the command mysql -uroot-p, you lose the password prompt after the carriage return, if just installed MYSQL, super-user root no password, so you can directly enter into the MYSQL a, MYSQL prompt is: MySQL>
2, Example 2: connect to a remote host on MYSQL
  assumed to remote host IP: 10.0.0.1, user name root, password 123. Type the following command:
   MySQL--h10.0.0.1-uroot-P123
(Note: u and the root can not have spaces, the other is the same)
3, exit MYSQL command
   exit (Enter)

(ii) Change Password:
   Format: mysqladmin -u user name -p password old password new password
1, Example 1: to add a root password 123. First, in the DOS directory C: \ mysql \ bin, then type the following command:
   mysqladmin-uroot--password123
  Note: Since the beginning of root without a password, so the -p an old password can be omitted.
2, Example 2: then the root password to 456
   mysqladmin -pab12password -uroot-456
(iii) adding new users :(Note: different above and below the MYSQL environment because it is a command, so the back with a semicolon as a command terminator)
   format:. Grant select on database * to username @ log on the host identified by "password"
  Example 1, add a user password for test1 abc, so that he can log on any host, and all databases have query, insert, modify, delete permissions. First to root user connected to the MYSQL, and then type the following command:
   grantselect, INSERT, Update, the Delete ON * * to test1 @ "%" Identified by "abc";.

  But Example 1 increased user is very dangerous, you want If a person knows test1 password, then he can log your mysql database and your data can do whatever they want, the solution, see Example 2 on any computer on the internet.
  Example 2, add a user test2 password is abc, so that he can only log on localhost, and can query the database mydb, insert, modify, delete operations (localhost means the local host, namely that host MYSQL database resides) so that users know that the use test2 password, he can not directly access the database from the internet, you can only be accessed through the web page on the MYSQL host.
   grantselect, insert, update, delete on mydb * to test2 @ localhost identifiedby "abc";.
  If you do not want test2 password, you can resort to a command to eliminate the password.
   grantselect, insert, update, delete on mydb * to test2 @ localhost identifiedby "".;

1, display a list of databases:
   Show Databases;
  only just started two databases: mysql and test. mysql database MYSQL inside it is very important system information, we change the password and add users actually use this library to operate.
2, the data table display library:
   use MySQL; // Open Library
   Show Tables;
. 3, shows the structure of the data table:
   DESCRIBE name;
4, database:
   Create database name Database;
5, built table:
   use the library name;
   create table table name (field set list);
6, puncturing and puncturing tables libraries:
   drop database name of the library;
   drop table name;
7, the empty record in the table:
   Delete from table name;
8, shown in the table of records:
   select * from table name;

MySQL Import Export command
1. Export the entire database
  mysqldump -u username -p database name> exported file name
  mysqldump -u -p smgp_apps_wcnc WCNC> wcnc.sql
2. Export a table
  mysqldump -u username -p database name watches> the exported file name
  mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql

3. The structure of a database is exported
  the mysqldump -u WCNC -p -d --add-drop-table smgp_apps_wcnc> D: wcnc_db.sql
  -d no data --add-drop-table to add a drop table before each create statement

4. import database
  common source command
  into the console mysql database,
  such as the root -u -p mysql
  mysql> use the database
  and use the source command, after the parameter script file (such as used herein .sql)
  mysql> source D: wcnc_db. sql (Note: If you write sourced: \ wcnc_db.sql, will report syntax

Use load data bulk import data, this approach can instantly import data, use very large!

Copy the code code is as follows:

The DATA the LOAD [the LOW_PRIORITY | the CONCURRENT] [the LOCAL] INFILE 'file_name.txt'
    [the REPLACE | the IGNORE]
    the INTO TABLE tbl_name
    [the FIELDS field operations, each field set delimiter

 

        [TERMINATED BY 'String']
        [[OPTIONALLY] the ENCLOSED BY 'char']
        [the ESCAPED BY 'char']
    ]
    [LINES operative start from a certain character, a character to

        [The STARTING BY 'String']
        [TERMINATED BY 'String']
    ]
    [Number LINES the IGNORE]-line operation, a row is ignored

    [(Col_name_or_user_var, ...)] field operation, a write field corresponding to data

    [SET col_name = expr,...)]


Example: load data infile '/test/test.file' intotable 'test' fields terminated by "\ t" (fieldsOne, fieldsTwo);
mean , /test/test.file loaded into table test using \ t segmentation field, and write fieldsOne fieldsTwo, the default newline as a line to split!

Guess you like

Origin www.cnblogs.com/Liqian-Front-End-Engineer/p/11548241.html