MySQL quick start _ MySQL-mysql tutorial

Source: Internet
Author: User
Tags mysql host mysql tutorial
Getting started with MySQL

MySQL quick start

1. connect to MySql

Use the installed MySQLl command line. by default, the user is the root user. here, I use the dos command line to log on.

1. connect to MySQL on the local machine

Format: mysql-u user name-p user password

Example: mysql-uroot-padmin

2. connect to a remote MySQL instance

Format: mysql [-h host address]-u user name-p user password

Example: mysql-h192.168.24. *-uroot-padmin

3. exit

Format: exit

Example: exit

2. create a user

1. add a user named test1 with the password test1 so that the user can log on to any machine and only have the permission to add, delete, modify, and query test.

Format: grant permission on database. * to username @ login host identified by "password"

Example: grant select, insert, update, delete on test. * test1 @ "%" identified by "test1 ".

2. add a user named test2 with the password test2 so that the user can log on locally and have the permission to add, delete, modify, and query all databases.

Format: grant permission on database. * to username @ login host identified by "password"

Example: grant select, insert, update, delete on *. * test2 @ localhost identified by "test2 ".

In this way, the data can only be accessed through the web pages on the MySQL host, making the data more secure.

III. database operations

1. display commands

Format: show indicates the project to be displayed (such as databases tables), select indicates the project to be displayed (such as user and version), and desribe indicates

Example:

Display the current database version: select virsion ();

Display the current user: select user ();

Show all users: select user from mysql. user;

Show all databases;

Show tables;

Displays the table details: desc [ribe] tablename;

2. open the database

Format: use databasename;

Example: use test;

3. add and delete databases

Format: create/drop database databasename

Instance:

Add a database: create database test1;

Delete a database: drop database test1;

4. add, delete, modify, and query tables

Example:

Add a table: create table teacher (id int (3), name char (10) not null, address varchar (50 ));

Delete a table: drop table teacher;

Add table data: insert into table name (column name) values (value );

Update table data: update table name set Field 1 = 'a', field 2 = 'B ';

Delete table data: delete from teacher [where...]

Import SQL script:/. file full path or source file full path

IV. database backup

Database Backup is a hot topic no matter which database management system it is in. Data first makes the database management systems the same, regardless of the differences. It only indicates whether the function is powerful or not, and whether the encapsulation is complete (we recommend that you do not use the unique features of the database ).

For example, in Oracle, Cascade deletion does not need to write the trigger on its own, but auto-incrementing sequence is so troublesome in Oracle.

1. back up the entire database: mysqldump-uroot-padmin test> c:/out. SQL

2. export a table: mysqldump-uroot-padmin test teacher> c:/out. SQL

V. Conclusion

I believe that with the above part, you can operate MySQL with ease.

In addition, MySQL supports multi-line input. you only need to enter a ";" in the last line. for example:

Insert into t_user (userId, password, username)

Values ('admin', 'admin', 'Zhang San ');

BitsCN.com

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.