Build mysql database and mysql common high-frequency commands
I. environment construction
This paper only builds learning in windows environment.
-
Download mysql
Because the install package can be installed directly, this chapter only explains the installation of decompression package.
Download website: http://dev.mysql.com/downloads/mysql/, Download mysql-8.0.15-winx64.zip -
Configure environment variables
Put the extracted bin directory in the path, such as (f:\ mysql-8.0.15-winx64\bin) -
Configure mysql
In f:\ mysql-8.0.15-winx64 \, create a new my.ini
The contents are as follows: [client] port=3306 default-character-set=utf8 [mysqld] port=3306 character_set_server=utf8 #Decompress directory basedir=f:\ mysql-8.0.15-winx64\ #Extract the data directory under the directory datadir=f:\ mysql-8.0.15-winx64\dat sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- windows command line running mysql installation, etc
cd f:\ mysql-8.0.15-winx64\bin # Entry directory > mysqld -initialize # Initialize mysql and generate files in data folder > mysqld -install # Install mysql > net start mysql # Start mysql server # Enter mysql > mysql -uroot -p password:Enter directly
II. Common commands
(tip: !!! : high risk operation)
2.1 database operation
CREATE DATABASE dbname; # Create database DROP dbname; # Delete database!!! USE dbname; # Use database
2.2 data table operation
CREATE TABLE tbname (column_name column_type); # Create data table DROP TABLE tbname; # Delete data table!!!
2.3 view operation
# Create a myview view view and merge the information corresponding to the two tables CREATE.VIEW myview AS SELECT a.name AS name b.class AS class FROM studemt a # student table specified as a class b # class table specified as b where a.id = b.id # When the. IDs of tables a and b are equal
2.4 data operation (add, delete, modify and query)
# increase INSERT [ignore] INTO tbname field1.. VALUES value1.. # Increase the value1 value in the field1 attribute of the tbname table # Delete DELETE FROM tbname WHERE # Remove WHERE compliant values from the tbname table DELETE FROM tbname # Delete all data in tbname table!!! # change UPDATE tbname SET field1..=value1.. WHERE # When the tbname table matches WHERE, change the value of field1 attribute to value1 # check SELECT * FROM tbname [ order by ASC,DESC ] # Display tbname table in [positive, reverse] order