MySQL- Overview

A, MySQL base

2.1 Meaning

(1) developed by the Swedish company MySQL AB, now part of Oracle Corporation.
(2) is an open source relational database management systems.
(3) into Community Edition and Enterprise Edition.

2.2 MySQL directory structure

(1) bin directory: store the executable file.
(2) data directory: store data files.
(3) docs directory: storing document files.
(4) include directory: header file storage included.
(5) lib directory: store files.
(6) share directory: Error Message or character set file.

Second, install MySQL

2.1 Installation

MSI installer (Windows Installer)
ZIP installation

2.2 Installing MySQL

(1) Double-click the MSI installation file.
(2) End User License Agreement. Consent
(3) Select the type of installation:
Typical (typical installation, beginner) Custom (custom installation) Complete (full installation)
(4) ready to install.
(5) progress of the installation.
(6) MySQL product advertising.
(7) MySQL product advertising.
(8) asking whether the configuration operation.

Third, configure MySQL

Step 3.1

(1) run the MySQL Configuration Wizard file (MySQLInstanceConfig.exe). bin directory.
(2) Configuration Wizard welcome screen.
(3) Select the type of configuration
Detailed Configuration (Detailed Configuration)
Standard the Configuration (standard configuration, beginner)
(4) is installed as a Windows service.
All three check boxes can be checked.
(5) set the root password
set up their own, or default.
(6) is ready to perform setup options.
(7) configuration.

3.2 Configuration Options - modify my.ini document

3.2.1 modify the encoding

[mysql]
default-character-set=utf8
[mysql]
character-set-server=utf8

3.2.2 modify the default storage engine

[mysql]
default-storage-engine=INNODB

The use of MySQL

4.1 Open / Close Server

(1) GUI - Computer Management
(2) a command prompt --cmd
start command:

net start mysql

Stop command:

net stop mysql

Note: All applications in the Windows computer management can enable / disable the above command.

Login Server 4.2

parameter meaning
-D,–database=name Opens the specified database
–delimiter =name Specified delimiter
-h,–host=name name of server
-p,–password[=name] password
-P,–port=# The port number
–prompt=name Set prompt
-u,–user=name username
-V,–version Output version information and exit.

MySQL login command:

mysql uroot -p -P3306 -h127.0.0.1

MySQL exit command:

mysql > exit
mysql > quit
mysql > \q

4.3 modify MySQL prompt

(1) When a client is connected is specified by the parameter

shell>mysql -uroot -proot --prompt

(2) connected to the client by modifying the command prompt

mysql>prompt

Stop commands are clear:

cls
parameter meaning
\D Complete date
\d The current database
\h name of server
\ in Current user

4.4 MySQL commonly used commands

demand command
Displays the current server version SELECT VERSION();
Displays the current date and time SELECT NOW();
Displays the current user SELECT USER();

Specification 4.5 MySQL statement

(1) keywords and function names are all uppercase.
(2) using the identifier written camel.
(3) SQL statements must ";" semicolon.

Fifth, the operation of the database

5.1 View

5.1.1 Number Database - Single Server

View the current list of databases in the server
Syntax: SHOW {DATABASE | SCHEMAS} [ LIKE 'pattern' | WHERE expr]

SHOW DATABASE;

Table 5.1.2 Number - Single Database

Check the number of tables in a database.
Syntax: SHOW TABLES [FROM db_name] [ LIKE 'pattern' | WHERE expr];

-- 查看某个数据库中的表
SHOW TABLES FROM db_t1;
-- 查看服务器中的所有表
SHOW TABLES FROM mysql;

5.1.3 currently running database name

Displays the current database has been opened.
Syntax: SELECT DATABASE ();

SELECT DATABASE();

5.1.4 create SQL statements

5.1.4.1 Database

SQL statements to create a database of view
syntax: SHOW CREATE DATABASE db_name;

SHOW CREATE DATABASE db_t1;

Table 5.1.4.2

View the table creation SQL statements.
Syntax: SHOW CREATE TABLE table_name;

SHOW CREATE TABLE t_student;

5.1.5 View table structure

语法:SHOW COLUMNS FROM table_name;

SHOW COLUMNS FROM t_student;

View the table of the index case 5.1.6

语法:SHOW INDEXES FROM table_name;

-- 表格形式展示。
SHOW INDEXES FROM t_student;
-- 网格形式展示。
SHOW INDEXES FROM t_student\G;

5.2 Creating a database

Syntax:
the CREATE DATABASE {|} SCHEMA [the IF the NOT EXISTS] db_name [the DEFAULT] the CHARACTER the SET [=] charset_name;
{}: must. | Option. []may have.

CREATE DATABASE IF NOT EXISTS db_t1;
CREATE DATABASE IF NOT EXISTS db_t2 CHARACTER SET = utf8;

5.3 modify the database

语法:ALTER {DATABASE | SCHEMA} [db_name] [DEFAULT] CHARACTER SET [=] charset_name;

ALTER DATABASE db_t1 CHARACTER SET = utf8;

5.4 Delete Database

语法:DROP {DATABASE | SCHEMA} [IF EXISTS] db_name;

DROP DATABASE IF EXISTS db_t2;

5.5 Open the database

Syntax: USE db_name;

USE db_t1;

Fifth, the operation of the database table

Database Members: table.
Table members: fields (columns) + records (rows).

5.1 Creating table

语法:
CREATE TABLE [IF NOT EXISTS] table_name(
column_name data_type ,

column_name data_type
)

CREATE TABLE IF NOT EXISTS t_syudent(
  id INT ,
  username TINYINT UNSIGNED NOT NULL,
  salary FLOAT(7,2) UNSIGNED NULL,
  sex ENUM('男','女','保密') DEFAULT '保密'
);

5.2 modify the table

5.2.1 single increase

语法:
ALTER TABLE table_name ADD[COLUMN] column_name column_definition [FIRST | AFTER column_name;

ALTER TABLE t_student ADD clazz TINYINT UNSIGNED NOT NULL DEFAULT 1 AFTER username;

5.2.2 increase the number of columns

语法:
ALTER TABLE table_name ADD[COLUMN] (column_name column_definition,…);

ALTER TABLE t_student ADD (clazz1 TINYINT UNSIGNED NOT NULL DEFAULT 1,clazz2 TINYINT UNSIGNED NOT NULL DEFAULT 1);

5.2.3 Delete single row

语法:
ALTER TABLE table_name DROP[COLUMN] column_name;

ALTER TABLE t_student DROP clazz2;

5.2.4 delete multiple columns

语法:
ALTER TABLE table_name DROP[COLUMN] column_name,DROP[COLUMN] column_name;

ALTER TABLE t_student DROP clazz1,DROP clazz2;

-- 增加clazz时,同时删除clazz1
ALTER TABLE t_student ADD clazz TINYINT UNSIGNED NOT NULL DEFAULT 1 AFTER username,DROP clazz1;

5.2.5 modify single row

(1) modify the column definition
syntax:
the ALTER TABLE table_name the MODIFY [the COLUMN] column_name column_definition [FIRST | an AFTER column_name];

ALTER TABLE t_student MODIFY id SMALLINT UNSIGNED NOT NULL FIRST;

(2)修改列名称
语法:
ALTER TABLE table_name CHANGE[COLUMN] old_column_name new_column_name column_definition [FIRST | AFTER column_name];

ALTER TABLE t_student CHANGE id pid SMALLINT UNSIGNED NOT NULL FIRST;

5.2.6 modify the table name

语法一:
ALTER TABLE table_name RENAME[TO | AS] new_table_name;
语法二:
RENAME TABLE table_name TO new_table_name,table_name TO new_table_name;

ALTER TABLE t_student RENAME t_student2;

Six rows of the table operation

See "MySQL- single table (row operations)."

Guess you like

Origin blog.csdn.net/lizengbao/article/details/86766637