Mainstream database of deep learning | MySQL basics, mainstream mysql

Source: Internet
Author: User

Mainstream database of deep learning | MySQL basics, mainstream mysql
Beijing | deep learning and AI Training

December 23-24

Review deep learning with the classic course >


The body contains 4732 words and 21 images. The expected reading time is 12 minutes.


This article mainly describes the installation and basic operations of MySQL. It is suitable for use as a quick start when you have no knowledge about MySQL but urgently need some MySQL knowledge.


Background and Installation


You can understand the background. Install it in Ubuntu. It is actually very simple. If you do not need to install complex source code here, you just need to input the following simple command to install it.


Sudo apt-get install mysql-server
Sudo apt isntall mysql-client
Sudo apt install libmysqlclient-dev


The password setting page is displayed in the middle. Set the password. Then verify if MySQL is installed. Enter the following command (which will be explained below) to log on to mysql.


Mysql-u root-p


Enter your password and check that the logon interface is successfully installed.


Installation visualization Interface


Sudo apt-get install mysql-workbench


The first thing after successful installation is to adjust the character set to utf8. After all, you are in a Chinese region and do not want to see Garbled text.


The address of the newly installed mysql configuration file is in/etc/mysql/my. cnf. Open it with any text file and copy the following statements to the file (for example ).


[Mysqld]
Init_connect = 'set collation_connection = utf8_unicode_ci'
Init_connect = 'set NAMES utf8'
Character-set-server = utf8
Collation-server = utf8_unicode_ci
Skip-character-set-client-handshake



After saving, restart the mysql service,


Sudo service mysql restart


Log on to mysql (as mentioned earlier) and enter


Show variables like '% character % ';


 

For example, the character set is successfully modified.


Common commands

1. connect to and exit MYSQL


The connection can be connected either locally or remotely. For example, when I verified whether MySQL was installed, I logged on to MySQL. In fact, this is also a local connection. The general format for connecting to MySQL is as follows.


Mysql-h (host address)-u (User Name)-p (password)


Example 1: connect to a local MySQL instance


Mysql-u root-p


In fact, you should know that-u is followed by the root user name. In fact, mysql is the Super administrator's default root user name, And the password is the password set at the beginning of mysql installation. So this command is quite understandable.


2. Create and delete Databases


If there is no database at the beginning, creating a database is definitely the most basic step, or you want to create a new database. Creating a database is also simple. The following command is fine.


Create:


Create database databasename; (database name)


Delete:


Drop database databasename; (database name)


For example, if I want to create a database named cat, just copy the above creation mode. (Do not drop punctuation)


Create database cat;


Similarly, deleting the cat database is similar.


3. view database information and use the database


After the above creation process, you should have created a database. How can you view the database with permissions of the current user? Is the show command.


Show databases;


 

We can see that the database with the cat name just created is shown in the figure above. The next step is to use a database, and the command is also very simple.


Use name;


It is easy to understand. After the Chinese translation, the database named xx is used. Note that after this command is used, all the subsequent operations are under this database. Until the MySQL connection is closed or switched to another database. For example, the following uses the cat database as an example.


Use cat;


 

From now on, the operations you perform are all under the cat database, so be clear.


4. Common MYSOL types


Like programming languages, MySQL also has common data types. Familiar with common data types is the basis for creating tables and other operations later.


MySQL data types include numbers, dates, times, and strings.


Digital Data Type


MySQL uses all standard ansi SQL numeric data types


INT: an integer of the normal size, which can be signed. If it is signed, it allows the range from-2147483648 to 2147483647. If it is unsigned, the allowed range is from 0 to 4294967295. You can specify up to 11 characters in width.


TINYINT: A very small integer that can be signed. If it is signed, it allows the range from-128 to 127. If it is unsigned, the allowed range is from 0 to 255. You can specify a width of up to 4 digits.


SMALLINT-a small integer that can be signed. The value range is-32768 to 32767. If it is unsigned, the allowed range is from 0 to 65535. You can specify a maximum of five characters in width.


MEDIUMINT-a medium-size integer that can be signed. The value range is-8388608 to 8388607. If it is unsigned, the allowed range is from 0 to 16777215. You can specify a maximum of 9 Characters in width.


BIGINT-a large integer that can be signed. The value range is-9223372036854775808 to 9223372036854775807. If it is unsigned, the allowed range is from 0 to 18446744073709551615. You can specify a width of up to 20 bits.


FLOAT (M, D)-You cannot use unsigned floating point numbers. The display length (M) and decimal places (D) can be defined ). This is not required, and the default value is 10, 2. 2 is the number of decimal places, and 10 is the total number of digits (including decimal places. The decimal precision can be up to 24 floating points.


DOUBLE (M, D)-You cannot use an unsigned DOUBLE-precision floating point number. The display length (M) and decimal places (D) can be defined ). This is not required. The default value is 16, 4, where 4 is the digits of decimal places. The decimal precision can reach a 53-bit DOUBLE. REAL is a synonym for DOUBLE.


DECIMAL (M, D)-uncompressed floating point numbers cannot be unsigned. In the unwrapped decimal point, each decimal point corresponds to one byte. Defining the number of display lengths (M) and decimals (D) is required. NUMERIC is a synonym for DECIMAL.


Date and Time Type


DATE-DATE in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, it will be stored as December 30, 1973-12-30 in 1973.


DATETIME-Date and Time combination in YYYY-MM-DD HH: MM: SS format, between 1000-01-01 00:00:00 to 9999-12-31 23:59:59. For example, it will be stored as December 30, 1973 15:30:00.


TIMESTAMP-the TIMESTAMP between midnight, January 1, January 1, 1970, to a certain time of 2037. This looks like the previous DATETIME format, and does not need to be a hyphen between digits. It will be stored as December 30, 1973 (YYYYMMDDHHMMSS) at 03:30 P.M. on January 1, 19731230153000 ).


TIME-the storage TIME is in HH: MM: SS format.


YEAR (M)-stores the YEAR in the format of two or four digits. If the length is set to 2 (for example, YEAR (2), the YEAR can be 1970 to 2069 (70 ~ 69 ). If the length is 4 and the year range is 1901-2155, the default length is 4.


String type


CHAR (M)-a string of a fixed length is a string of 1 to 255 characters (for example, CHAR (5). the right space is stored and filled with the specified length. The length limit is not required. It defaults to 1.


VARCHAR (M)-a variable-length string is a string of 1 to 255 characters (MySQL of higher versions exceeds 255 characters). For example: VARCHAR (25 ). the length must be defined when you create a VARCHAR field.


A blob or TEXT-field can contain a maximum of 65535 characters. BLOB is a "Binary Large Object" that is used to store large binary data, such as files of other types. The TEXT field also holds a large amount of data. The difference between the two is that the BLOB is case sensitive, while the TEXT field is case insensitive. You do not need to specify the BLOB or TEXT length.


The maximum length of a TINYBLOB, TINYTEXT-BLOB, or TEXT column must be 255 characters. The length of TINYBLOB or TINYTEXT is not specified.


The maximum length of a MEDIUMBLOB, MEDIUMTEXT-BLOB, or TEXT column is 16777215 characters. The length of MEDIUMBLOB or MEDIUMTEXT is not specified.


The maximum length of a LONGBLOB, LONGTEXT-BLOB, or TEXT column is 4294967295 characters. The length of LONGBLOB or LONGTEXT is not specified.


ENUM-enumeration, which is a strange list of terms. When defining an ENUM, you need to create a list of its values, which are required for selection (or NULL ). For example, if you want A field to contain "A", "B", or "C", you can define it as ENUM ("A", "B", "C ") only these values (or NULL) can be used to fill this field.


5. Create and Delete tables


With the above knowledge about the basic MySQL Data Types, you can start creating tables. First, let's talk about the basic format of creating a table.


Create table table_name (column_name column_type );


You can use the drop command to delete a table.


Drop table table_name;


Example time:


You need to create a table that records the student information, student ID, name, age, date of birth, height, and final score in the class. You can use the newly created cat database for storage.

Explanation:


First, the student id. Here, id is used to represent the student id. INT type. not null indicates that the student id is NOT empty,
Name, with variable character storage, VARCHAR
The last important thing is to specify the primary key. Here, id is specified as the primary key.


The DESCRIBE command can be used to view the table structure.


DESCRIBE table name;

6. insert data to the table


Now we have created a table student_info, but this table is an empty table. Therefore, we need to insert data into this table.


General insert format:


Insert into table_name (field1, field2 ,... FieldN) VALUES (value1, value2 ,... ValueN );


Example:


Here, we inserted a string with id 123, name as "leo", age 24, and birthday )... .


7. query and delete record statements


Now there are records in the table, and the next task is how to view the items in the table? This is the SELECT command. Its general usage is:


SELECT field1, field2 ,... FieldN table_name1, table_name2...
[WHERE condition1 [AND [OR] condition2 .....


Delete record:


Delete from table_name [WHERE Clause]


Note that if the WHERE clause is not specified, all records in the MySQL table will be deleted.


 

In the preceding example, all the fields with id = 123 are selected. Because the data in the table is insufficient, more complex selection operations cannot be performed for the moment. In the future, more complex operations will be selected as much as possible. Here you can familiarize yourself with the basic usage.


8. Update operations


It is very common to update data in a database, because the data can never be changed for the rest of your life. The general form of update operations is:


UPDATE table_name SET field1 = new-value1, field2 = new-value2 [WHERE Clause]


The above command is literally easy to understand. Very simple.


Here, the information of the age and birthday fields in student_info is changed. The result is as follows:

9. Alter command


Http://www.yiibai.com/mysql/mysql_alter_command.html


Http://www.python-requests.org/en/master/



Link: http://blog.csdn.net/xierhacker/article/details/60868455


For more concise and convenient classification articles and the latest courses and product information, please go to the newly presented "LeadAI college Official Website ":

Www.leadai.org


Please follow the artificial intelligence LeadAI public account to view more professional articles

Everyone is watching

Application of LSTM model in Q & A System

TensorFlow-Based Neural Networks solve the problem of user loss Overview

Sort out the most common questions for algorithm Engineers (1)

Sort out the most common questions for algorithm Engineers (2)

TensorFlow starts from 1 to 2 | Chapter 3 deep learning revolution: convolutional Neural Network

Decorator | Python Advanced Programming

Let's review the basics of Python today.



Click "read original" to open the registration link.

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.