Getting started with MySQL

Source: Internet
Author: User

related knowledge ( key content starting from title one )

Current mainstream databases are:

SQL Server, MySQL, qracle, SQLite, Access, MS SQL Servers, etc., I am mainly talking about MySQL;

Here are a few things to remember!!!

SQL includes all operations on the database, consisting mainly of 4 partial groups

1. Database definition Language (DDL): Used to define and manage database objects, including databases, basic tables, views, and indexes

2. Database manipulation Language (DML): Two types of operations for manipulating data queries and data updates, where data updates include expansion, deletion, and update of three operations

3. Database query Language (DQL): Query is the core of the SQL language, and the SQL language simply provides a statement for the database query, which is the SELECT statement.

4. Database Control Language (DCL): Statements that are used to set or change permissions for a database user or role, including (Grant, DENY, REVOKE, and so on) statements.

To connect to a database:

-h Specifies the location of the connected database server, which can be either IP or the server domain name

-u Specifies the user name of the connected database server, such as root for administrative user ownership

-P connect the password used by the database server

I. Configuring MySQL environment variables

(1) Configuring environment variables

Some people don't understand why the environment is configured here? I say to you, most of the MySQL we use is run in the terminal, then we must use the MySQL command in the terminal, for example, if we want to use the INSERT statement in the terminal, then we will find the Insert command in the terminal configuration file to call, we need to enter the terminal /usr/local/mysql/bin, in this path to use the INSERT, is not very troublesome ah, so you need to configure the environment variables, and then do not have so many paths, directly write insert can be used to insert this command, OK, here is the actual operation:

1. In terminal input: sudo vi bash_profile//not yet into MySQL Oh! Just under the terminal!! Watch out!

2. Then add in the edit box: Export path= $PATH:/usr/local/mysql save off;

3. Refresh this file configuration: source. bash_profile

4. Then output the current environment path: Echo $path

When the above output code is/usr/local/mysql/bin, the environment variable is configured successfully

(2) Modify the original password

Mysqladmin- u user name-P old password Password New Password

This way, the password modification is complete.

Two. Create DATABASE, data table

Login Mysql:mysql-h Server Location-u user name-p password;

After logging on to the database:

1. Create the database (the name of the database created below is Waige)

If the Waige database is not present, create the: If not exists Waige; Red indicates the name of the database created;

Delete if the Waige database is present: Drop DB if exists waige;

2, after creating the database, the following should create the data table laq1:

CREATE table if not exists LAQ1(id int, name char (+), age int); Red indicates the name of the table to be created.

I then add the contents of the table to the LAQ1, which is the INSERT statement to use:

INSERT into LAQ1 value (' 1 ', ' laq23 ', ' 23 ');//This is the first piece of information inserted in the LAQ1 table

Insert into LAQ1 (name,age) value (' laq234 ', ' 33 ');//This is the second piece of information inserted in LAQ1, note that the two insertions are different and I intentionally insert them in two different ways. The first is that the values in parentheses must be written in each value, and the value in the second is not a must-write, but is determined by the contents of the parentheses following the table name.

Three. Insert statement, find statement

1, insert 2 information in the table, I will take these two messages out, this will use the SELECT statement:

1  Use  2Select* from laq1;

After executing the above 2 lines of code, the output is as follows:

2. Then, I'm going to take the age>30 user out of this table, and I'm going to use another way of writing the SELECT statement:

Select *  from where age>;

This removes the user information for age greater than 30.

Four. mysql New user

Note: Unlike above, the following is because it is a command in the MySQL environment, so it is followed by a semicolon as the command terminator

Format: Grant Select on database. * To User name @ login host identified by "password"

It's over, take a break!!!!!!!!!!!!!!!!!!

Getting started with MySQL

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.