The usual sentence collation in MySQL

Source: Internet
Author: User

Common statements in MySQL:

1: Create a table with self-growing primary key
DROP TABLE IF EXISTS user_login;
CREATE TABLE User_login (
user_id INT UNSIGNED not nullauto_increment,
User_name VARCHAR () DEFAULT NULL,
PRIMARY KEY user_id
) Engine=myisam auto_increment=0 DEFAULT Charset=utf8;

2: Modify table name
ALTER TABLE name RENAME present table name;

3: Add columns
ALTER table name ADD column name type length and so on [such as: VARCHAR (10)];

4: Modify Column Name
ALTER table name change column name is listed name type length and so on [such as: VARCHAR (10)]; ---Be sure to bring the type length information

5: Modify Column type length
ALTER Table name change column list name type length;

6: Delete Columns
ALTER TABLE column name DROP column name;

7: Modify the character set of the database UTF8
ALTER DATABASE test DEFAULT CHARACTER SET UTF8;

8: Modify the character set of the table UTF8
ALTER TABLE user_login DEFAULT CHARACTER SET UTF8;

9: Modify the existing table primary key self-growth (the original key is not set), only for future data to take effect, the existing data is invalid, existing data self-growth has not been resolved
ALTER table name change primary key column ID INT auto_increment;

10: Data encryption
A) Password function
such as: INSERT into User_login (User_name,user_password) VALUES (' Shark ', password (' qweasdzxc '));
The saved data is: Shark, *e9d8702e5ce97f00a17a75241c04a013b407a1a6
In particular, it is necessary to ensure the effective size of the encrypted field length, I here 9 characters 30 bit is not enough, I directly increase to 100, this specific bit with the encryption algorithm, post-study
Select decryption: SELECT * from User_login WHERE user_password=password (' qweasdzxc ');
b) MD5 encryption
INSERT into User_login (User_name,user_password) VALUES (' Kok ', MD5 (' qweasdzxc '));
The saved data is: KOK,315EB115D98FCBAD39FFC5EDEBD669C9
There is a certain difference between the character format generated by the password function encryption, or the encryption algorithm.
SELECT * FROM User_login WHERE user_password= MD5 (' qweasdzxc ');

The usual sentence collation in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.