mysql commonly used commands and notes

The first one, starting and stopping mysql service

  net stop mysql

  net start mysql

  The second measure, landing mysql

  The syntax is as follows: mysql -u user name -p User password

  Type the command mysql -uroot -p, carriage return after the prompt you for a password, enter 12345, and then press Enter to enter in to the mysql, mysql 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, add a user password for user1 password1, allowed to log in on the machine, and all databases have query, insert, modify, delete permissions. First, for the root user connected to the mysql, and then type the following command:

  grant select,insert,update,delete on *.* to user1@localhost Identified by "password1";

  If you want the users to log in mysql on any machine, localhost will be changed 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.* to user1@localhost identified by "";

  Fourth trick: to operate the database

  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;

  By 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 table:

  use mysql;

  show tables;

  3 showing the structure of the data table:

  describe table name; show create table table name to display code that creates the table.

  4, building a database and delete libraries:

  create database 库名;

  drop database library name;

  5, built table:

  use the library name;

  create table table name (field list);

  drop table 表名;

  6, empty record in the table:

  delete from 表名;

  7, a record in the table:

  select * from 表名;

  Fifth strokes, export and import data

  1. Export data:

  mysqldump --opt test > mysql.test

  About to be exported to mysql.test database test database file, which is a text file

  如:mysqldump -u root -p123456 --databases dbname > mysql.dbname

  Dbname is to be exported to a database file in mysql.dbname.

  2. Import data:

  mysqlimport -u root -p123456 < mysql.dbname。

  Do not explain it.

  3. The text data into the database:

  Separated by tab key field data between the text data.

  use test;

  load data local infile "filename" into table table name;

  1: What is the current database exists on the server using the SHOW statement to find out:

  mysql> SHOW DATABASES;

  2: 2, create a database MYSQLDATA

  mysql> CREATE DATABASE MYSQLDATA;

  3: Select the database you created

  mysql> USE MYSQLDATA; (described operation is successful press Enter Database changed occurs!)

  4: see now what exists in the database table

  mysql> SHOW TABLES;

  5: Create a database table

  mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));

  6: shows the structure of the table:

  mysql> DESCRIBE MYTABLE;

  7: records added to the table

  mysql> insert into MYTABLE values ("hyq","M");

  8: text mode the data into the database tables (e.g. D: /mysql.txt)

  mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;

  9: Import .sql file commands (e.g. D: /mysql.sql)

  mysql>use database;

  mysql>source d:/mysql.sql;

  10: Delete table

  mysql>drop TABLE MYTABLE;

  11: Empty Table

  mysql>delete from MYTABLE;

  12: Update data in table

  mysql>update login set name='lipengsheng' where userid='01';
update login set name='李玉凤' where userid='02';
update login set name='李云奇' where userid='03';
update login set name='王秀珍' where userid='04';

  posted on 2006-01-10 16:21 happytian reading (6) Comments (0) edit collections collections to 365Key

  13: Backup Database

  mysqldump -u root 库名>xxx.data

  14: Example 2: connect to a remote host on MYSQL

  Assuming that the remote host IP is: 110.110.110.110, the user name is root, password is 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 (Enter)

15.mysql whether a field is empty, if the field is a string type, use = '' or <> ', if the Type field is not a string, such as: integer, then use is null or is not null.
hibernate, too.

 

Guess you like

Origin www.cnblogs.com/lipengsheng-javaweb/p/11440466.html