Raspberrypi 3 Study Notes (iv)--MYSQL related settings

Source: Internet
Author: User

1. Install MySQL

Run the following statement with administrator privileges to get MySQL and the Python programming interface;

Apt-get Install Mysql-server Python-mysqldb

During the installation process will let you enter the password, enter the database password on the line.

2. Test MySQL

Enter the following instructions for the MySQL test, the first is to enter the MySQL (user root login, will let you enter the password, the password input process is not visible, enter the completion of the following press ENTER on the line):

Mysql-u root-p

To view the current database:

show databases;

Create a database:

Create Database dt_test;

Using the Dt_test database:

Use Dt_test;

To view the tables that exist in the database:

Show tables;

Create a table tbtest:

CREATE TABLE tbtest (ID int,name varchar (20));

To insert data into the Tbtest table:

INSERT into tbtest values (1, ' Test ');

To view the data in the Tbtest table:

SELECT * from Tbtest;

To delete a table with the name dttest in the Dt_test database:

drop table tbtest;

To delete a database dt_test:

Drop database dt_test;

Exit:

Quit

3. Create a self-increment field in MySQL

  Crete Table TB1 (
ID int auto_increment,//Create self-increment field with ID int
Name varchar (primary key),//Set name as primary key
Key (ID)); Cancel ID PRIMARY key

4. About MySQL primary key setup issues

1, the simplest:

CREATE TABLE t1 (ID int not NULL, name char (20));

2, with the primary key:

CREATE TABLE t1 (ID int not NULL primary key, name Char (20));

B: Composite PRIMARY key

CREATE TABLE t1 (ID int not NULL, name char, primary key (Id,name));

3, with the default value:

CREATE TABLE t1 (ID int NOT NULL default 0 primary key, name char (default ' 1 ');


This article is from the "World is the same" blog, please be sure to keep this source http://970076933.blog.51cto.com/9767314/1869133

Raspberrypi 3 Study Notes (iv)--MYSQL related settings

Related Article

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.