MySql WorkBench基本使用以及基本sql语句_MySQL
bitsCN.com
导读:
本篇文章会教你如何使用My Sql WorkBench 5.2 进行数据库的基本操作(建库建表等)
前言
MySql是甲骨文公司的产物,所以有些地方跟Oracle挺相似,比如“服务器实例”这个概念,当初由sqlserver转Oracle的时候,一开始就不理解这个服务器实例是个什么东西,因为在SqlServer里,就只有一个服务器,登录之后就是操作数据库,基本上就是一个项目对应一个数据库。
但有的项目很庞大,需要创建很多的数据库,多个数据都是属于同一个项目,然后这时候就可以创建一个服务器实例,可以把需要的数据库创建在这个实例下,创建好服务器实例后,会给这个实例分配一个端口(这是必然的,因为已经是服务器了嘛)也会在Windows系统 服务列表添加相应的服务,这时候你就应该更深刻的了解什么是服务器实例了。基本上是:一个项目对应一个服务器实例。
创建服务器实例
由于还没有研究透,所以先空着,以后会加上,我的是在安装的时候就选了创建默认服务器实例,现在就拿它做下面的示范
创建数据库
双击要连接的服务器实例
输入密码进入之后,选择DataBase→Query Database
选择OK,创建了一个新页面
左侧的树就是该服务器实例下的所有数据库列表,中间部分就是执行sql语句的地方,执行如图的sql语句(单击小闪电图标),创建一个数据库,在左侧的树形结构里,随便右击一个东西,选择Refresh All,新数据库出来了
注:我的数据库文件存储在E:/ProgramData/MySQL/MySQL Server 5.5/data 盘符自己对应
一个数据库就是一个文件夹
创建数据表
[sql]
use ceshi;
create table student
(
stuid int primary key auto_increment,
stuName varchar(40) not null
);
这样就创建了一个studeng表,auto_increment是自增列的意思
插入数据
[sql]
insert into student(stuname) values('zhangsan');
insert into student value(2,'lisi');
insert into student value(10,'wangwu');
insert into student(stuName) value('maliu');
这样就插入了4条数据,并且测试了自增列插入的方法,
如果语句里不指定插入自增列,则默认是从1开始,自增量是1
也可以指定插入自增列的值,指定插入值之后,再自增插入,则继续自增。4条数据如下
添加删除字段
[sql]
alter table student add age int ;
alter table student drop age;
添加删除唯一约束
[sql]
alter table student add constraint UN_Name unique(stuName);
alter table student drop index UN_Name;
bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

Oracle Invalid numeric errors may be caused by data type mismatch, numeric overflow, data conversion errors, or data corruption. Troubleshooting steps include checking data types, detecting digital overflows, checking data conversions, checking data corruption, and exploring other possible solutions such as configuring the NLS_NUMERIC_CHARACTERS parameter and enabling data verification logging.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.
