First trick, start and stop of MySQL service
net stop MySQL
net start MySQL
Second move, login MySQL
The syntax is as follows: Mysql-u user name-p user Password
Type the command mysql-uroot-p, enter the password after entering, enter 12345, and then enter into the MySQL, MySQL prompt is:
Mysql>
Note that if you are connecting to another machine, you need to add a parameter-H machine IP
Third recruit, add new user
Format: Grant permissions on database. * To User name @ login host identified by "password"
For example, add a user user1 password to Password1, so that it can log on to the computer, and all databases have query, insert, modify, delete permissions. First, use the root user to connect to MySQL, and then type the following command:
Grant Select,insert,update,delete on *. * to identified by "Password1";
If you want the user to be able to log on to MySQL on any machine, change localhost to "%".
If you do not want to User1 have a password, you can make another command to remove the password.
Grant Select,insert,update,delete on mydb.* to identified by "";
Four strokes: Manipulating the database
Log in to MySQL, and then run the following command at the prompt of MySQL, with each command ending with a semicolon.
1. Display the list of databases.
show databases;
The default is two databases: MySQL and test. MySQL inventory in the MySQL system and user rights information, we change the password and the new user, is actually to operate the library.
2. Display the data table in the library:
Use MySQL;
Show tables;
3, display the structure of the data table:
describe table name;
4. Build the library and delete the library:
Create database name;
drop database name;
5, build the table:
Use library name;
CREATE TABLE table name (field list);
drop table name;
6. Clear the Table records:
Delete from table name;
7. Display the records in the table:
SELECT * from table name;
Recruit, export, and import data
1. Export Data:
Mysqldump--opt Test > Mysql.test
Export the database test database to the Mysql.test file, which is a text file
such as: Mysqldump-u root-p123456--databases dbname > Mysql.dbname
is to export the database dbname to the file mysql.dbname.
2. Import data:
Mysqlimport-u root-p123456 < Mysql.dbname.
You don't have to explain.
3. Import text data into the database:
The field data of the text data is separated by the TAB key.
Use test;
Load data local infile "file name" into table name;
1: Use the show statement to find out what database currently exists on the server:
Mysql> SHOW DATABASES;
2:2. Create a database Mysqldata
mysql> CREATE DATABASE Mysqldata;
3: Select the database you created
mysql> use Mysqldata; (press ENTER to appear database changed operation success!)
4: See what tables exist in the current database
Mysql> SHOW TABLES;
5: Create a database table
Mysql> CREATE TABLE MYTABLE (name VARCHAR), sex CHAR (1));
6: Show the structure of the table:
Mysql> DESCRIBE MYTABLE;
7: Add a record to the table
mysql> INSERT INTO MYTABLE values ("HyQ", "M");
8: Loading data into a database table in text mode (for example, D:/mysql.txt)
mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" into TABLE MYTABLE;
9: Import. sql File command (for example, D:/mysql.sql)
Mysql>use database;
Mysql>source D:/mysql.sql;
10: Delete Table
Mysql>drop TABLE MYTABLE;
11: Clear the table
Mysql>delete from MYTABLE;
12: Update data in table
Mysql>update MYTABLE set sex= "F" where name= ' HyQ ';
13: Backing Up the database
Mysqldump-u Root Library name >xxx.data
14: Example 2: Connecting to MySQL on a remote host
Assume the remote host IP is: 110.110.110.110, the user name is root, the password is abcd123. Type the following command:
Mysql-h110.110.110.110-uroot-pabcd123
(Note: You and root can be used without spaces, others are the same)
3. Exit MySQL command: Exit (enter)
DOS command line mysql basic command