TIPS: MYSQL

 

  1. mysql -h mysqlhost.mycompany.com -u root -p

use databasename

 

  1. CREATE TABLE Member (

loginName VARCHAR(20) NOT NULL,

createDate DATE NOT NULL,

password CHAR(255) NOT NULL,

lastName VARCHAR(50),

firstName VARCHAR(40),

street VARCHAR(50),

city VARCHAR(50),

state CHAR(2),

zip CHAR(10),

email VARCHAR(50),

phone CHAR(15),

fax CHAR(15),

PRIMARY KEY(loginName) )

 

  1. NOT NULL: This column must have a value; it cannot be empty.

 

DEFAULT value: This value is stored in the column when the row is created

if no other value is given for this column.

 

AUTO_INCREMENT: You use this definition to create a sequence number.

As each row is added, the value of this column increases by one integer

from the last row entered. You can override the auto number by assigning

a specific value to the column.

 

UNSIGNED: You use this definition to indicate that the values for this

numeric field will never be negative numbers.

 

  1. mysqladmin -u accountname -p start; //-p password is empty

mysqladmin -u accountname -p shutdown;

myisamchk -r path/databasename/tablename.MYI; //repair table

 

  1. CREATE DATABASE databasename;

SHOW DATABASES;

DROP DATABASE databasename;

SHOW TABLES;

SHOW COLUMNS FROM tablename;

DROP TABLE tablename;

DELETE FROM tablename WHERE clause; //remove a row

 

  1. ALTER TABLE tablename +

 

ADD columnname definition: Adds a column; definition includes the data

type and optional definitions.

 

ALTER columnname SET DEFAULT value: Changes the default value for a column.

 

ALTER columnname DROP DEFAULT: Removes the default value for a column.

 

CHANGE columnname newcolumnname definition: Changes the definition of a column and renames the column; definition includes the data type and optional definitions.

 

DROP columnname: Deletes a column, including all the data in the column. The data cannot be recovered.

 

MODIFY columnname definition: Changes the definition of a column;definition includes the data type and optional definitions.

 

RENAME newtablename: Renames a table.

 

INSERT INTO Member (loginName,createDate) VALUES (bigguy,2001-Dec-2);

 

LOAD DATA INFILE datafilename INTO TABLE tablename;

 

  1. SELECT price,price*1.08 AS priceWithTax FROM Pet

(The AS clause tells MySQL to give the name priceWithTax to the second

column retrieved.Database does not change)

 

  1. AVG(columnname) Returns the average of all the values in columnname

 

COUNT(columnname) Returns the number of rows in which columnname is not blank

 

MAX(columnname) Returns the largest value in columnname

 

MIN(columnname) Returns the smallest value in columnname

 

SUM(columnname) Returns the sum of all the values in columnname

 

SQRT() Returns the square root of each value in the column

 

DAYNAME() Returns the name of the day of the week for each value in a date column, rather than the actual date stored in the column.

 

  1. SELECT * FROM Member ORDER BY DESC lastName

 

SELECT * FROM Member ORDER BY lastName

 

SELECT * FROM Pet GROUP BY petType

 

 

  1. SELECT query UNION ALL SELECT query

(If ALL is not included, duplicate lines are not added to the result.)

 

 

  1. The INNER JOIN returns all rows from both tables where there is a match. If there are rows in Employees that do not have matches in Orders, those rows will not be listed.

 

The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed.

 

The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees). If there had been any rows in Orders that did not have matches in Employees, those rows also would have been listed.

 

  1. UPDATE Member SET street=3333 Giant St,phone=555-555-5555 WHERE loginName=bigguy

 

GRANT permission (columns) ON tablename TO accountname@hostname IDENTIFIED BY password

 

REVOKE permission (columns) ON tablename FROM accountname@hostname

 

REVOKE all ON *.* FROM accountname@hostname

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值