Python database [initial knowledge database]

Source: Internet
Author: User

Mysql

Introduced:

A database is a collection of data that is stored in a way that can be shared with a single user, with as little redundancy as possible, and independent of the application.

Database classification:

Relational database:

Relational database refers to a database that uses a relational model to organize data.

In simple terms, the relational model refers to a two-dimensional tabular model, and a relational database is a data organization composed of two-dimensional tables and their linkages.

Non-relational database:

Non-relational database is not a database in strict sense, it should be a collection of data structure storage method.

MariaDB:

MARIADB database management System is a branch of MySQL, mainly by the open source community in the maintenance, the use of GPL license. One of the reasons for developing this branch is that after Oracle acquired MySQL, there is a potential risk of shutting MySQL out of the source, so the community uses a branching approach to avoid this risk.
MARIADB is designed to be fully compatible with MySQL, including APIs and command lines, making it easy to be a replacement for MySQL. In the storage engine, the 10.0.9 version uses xtradb (named aria) instead of MySQL's InnoDB.
MARIADB, led by MySQL's founder, Macker Vidnius, has sold MySQL AB, the company he created, to sun for $1 billion earlier, and since Sun was acquired by Oracle, MySQL's ownership has fallen into Oracle's hands. Mariadb name comes from Macker Vidnius's daughter Maria (English: Maria).

Installation:

Linux (CentOS 7):

  #添加yum源, installing MariaDB 
# MariaDB 10.2 CentOS Repository list-created 2017-07-21 10:52 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb]name = Mariadbbaseurl =/http Yum.mariadb.org/10.2/centos7-amd64gpgkey =https://yum.mariadb.org/ Rpm-gpg-key-mariadbgpgcheck = 1

#执行命令
Yum Install Mariadb-server Mariadb-client

#防火墙放行: Port or Service mode
Port:
firewall-cmd--permanent--add-port=3306/tcp
Firewall-cmd-- Reload
Service:
firewall-cmd--permanent--add-service=mysql
firewall-cmd--reload

#数据库初始配置:
Mysql_ Secure_installation Navicat Premium Software Connection database on the

#Windows solution
#提示 "Host is not allowed to connect to this  Mysql server "Workaround:
Login database: use MySQL;    # go to MySQL library ' % ' ' Root ';  # This line of execution may be an error, no tube, directly execute the following sentence FLUSH privileges;   

Windows:

MySQL: Go to the following URL to download their own installation package installed on line https://www.mysql.com/downloads/Mariadb: ibid., download and install https:// downloads.mariadb.org/

Specification:
1. Case insensitive (recommended command capitalization)
2. End with a semicolon
3. Comments--Single line comment/*[content]*/multiple lines of comments

Constraints:
Primary key (primary key): Non-null unique
NOT NULL: non-null constraint
Unique: Single constraint


Database operations
show databases; --View all databases
Create DATABASE [DB name] [character set XXX]; --New database--[character set XXX] Sets the set of database encodings for the optional settings.
drop database; [Database name]; --Delete Database
ALTER DATABASE; [Database name]--Modify Database
Show CREATE DATABASE; [Database name]--View CREATE DATABASE statement information
Use [database name]; --use (enter) the database

--Create a table
CREATE table [table name] (
field FirstName data type,
field FirstName data type,
Field Name fields data type
);

Show tables; --View the tables in the library
desc [table name]; --View table field contents (tables structure)
Show columns from [table name]; --also view table structure ibid.
Show create table [table name]; --View statement information for the build table

--Add Table field
ALTER TABLE [table name] Add field FirstName data type (first|after field name)--first | After is the positional parameter
ALTER TABLE [table name]
Add [Field name] [field data type],
Add [Field name] [field data type],
Add [Field name] [field data type];
--Modify field information
ALTER TABLE [table name] modify [Field name] [Field type] (parameter);

--Modify field names
ALTER TABLE [table name] change [old field name] [new field name] [field type];

--delete Field
ALTER TABLE [table name] drop [field name];

--Modify Table name
Rename table [table name] to [new table name];

--Modify Table character set
ALTER TABLE [table name] Character Set [character set type];

--Delete Table
drop table [table name];

--Database renaming
Locate the directory where the database is located and change the name of the database corresponding folder directly.

Data type:
varchar ()
Text
Int
float ([digit],[precision])--float (5,2)

Python database [initial knowledge database]

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.