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