Home > Database > Mysql Tutorial > body text

mysql basic operations

黄舟
Release: 2017-01-16 13:20:26
Original
1147 people have browsed it

Use operations
tee [directory file] can record mysql operations and results
set names gbk explicitly tells the mysql server that the client's encoding is gbk (to prevent garbled characters)
desc [table name] table Structural details

Login command mysql -u[username] -p[userpasswd]

Multiple tables--->Place them in one library--->Multiple libraries form a database server

Operation process
When entering the database, you first face multiple libraries, select the required library among multiple libraries, and then select the required table in the library

Specific commands
1. Check which libraries are in the database show databases;
2. Select the required library use [library name];
3. Check which tables are in the selected library show tables;

Create a library create database [unimasvg1] charset utf8;
Delete a library drop database [unimasvg1]
Modify a library (mysql library cannot change the library name)

Create a simple table

create table staff(
snum int,
sname varchar(10)
)engine myisam charset utf8;
Copy after login

Rename table
rename table [oldname] to [newname]

Add content to the table

insert into [表名] values
(1,'name_1'),
(2,'name_2'),
(3,'name_3');
Copy after login

Display table content

select * from [表名]
Copy after login

Delete a table

drop table staff
Copy after login

Clear table contents

truncate [表名] --- 原理是 删除表,再重建一个同样名字的表
delete from [表名] where [条件] --- (可选删除)
Copy after login

The speed of deleting data, generally speaking: drop> truncate > delete

The above is the content of the basic operations of mysql. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template