Table of Contents
一.什么是sql
二.什么是mysql
三.安装mysql
1.常见组网图
2.安装mysql
四.登陆和退出mysql服务器
1.登陆mysql服务器
2.断开连接
五.创建和删除普通用户
1.创建用户
2.删除用户
六.修改密码
1.root用户修改root密码
2.root用户修改普通用户密码
3.普通用户修改密码
七.操作数据库
1.创建数据库
2.删除数据库
3.显示数据库
4.选择数据库
八.操作表
1.创建表
2.显示数据库中的表
3.查看表结构
4.查看表详细结构
5.基本查询
6.插入数据
7.显示表中数据
8.修改记录
9.删除记录
10.删除表
Home Database Mysql Tutorial LINUX总结第4篇:LINUX安装使用mysql_MySQL

LINUX总结第4篇:LINUX安装使用mysql_MySQL

Jun 01, 2016 pm 01:26 PM
linux mysql client server program

bitsCN.com

LINUX下安装mysql,一般都要同时安装客户端和服务器。

因为 mysql体系是分布式的,因此都存在服务器端和客户端两个系统。

服务器端系统包括一组在服务器主机上运行的程序和相关文件。而客户端系统则是连接数据库服务器,用来执行查询、修改和管理数据库中的数据的程序。

一.什么是sql


sql一般指结构化查询语言。


结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。结构化查询语言是高级的非过程化编程语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式,所以具有完全不同底层结构的不同数据库系统, 可以使用相同的结构化查询语言作为数据输入与管理的接口。结构化查询语言语句可以嵌套,这使它具有极大的灵活性和强大的功能。

二.什么是mysql

mysql是一个关系数据库管理系统。他是一个程序,可以存储大量种类繁多的数据。

mysql使用sql结构化查询语言。

使用DBMS,来管理数据库。数据库管理系统(database management system)是一种操纵和管理数据库的大型软件,用于建立、使用和维护数据库,简称dbms。

三.安装mysql

1.常见组网图

1)mysql服务器和客户端同时安装在一台机器上。

-----A--------

2)mysql客户端安装在服务器A上,服务器安装在另一台已经连接的服务器B上。

A-------B

3)一台终端A,上面不运行任何sql相关的软件,然后和服务器B(运行mysql客户端)相连,B再和服务器C(运行mysql服务器)连接。

A---------B--------------C

在第3)种模式下,mysql客户端并不在自己的机器上,需要登录到其他机器去使用mysql客户端,需要使用telnet等来操作。

本文中,采用第一种模式。

2.安装mysql

1)yum install mysql 安装mysql客户端

2)yum install mysql-server 安装mysql服务器

3)service mysqld start 启动mysql服务器

四.登陆和退出mysql服务器

mysql用户包括:普通用户、root用户。

root用户是超级管理员,拥有所有权限,比如创建用户、删除用户、修改所有用户密码和管理权限等。

普通用户只拥有创建该用户时赋予它的权限。

1.登陆mysql服务器

mysql -u root

进入mysql。mysql刚安装完毕,有默认用户root,和默认密码为空。

-u 是用来指定用户名。

当然,也可以这样:

mysql -h localhost -u root -p

-h用来指定服务器名,如www.xxx.com或者192.168.59.130,localhost表示本机,127.0.0.1也指本机。

当然,如果你登陆的是本机的话,-h是可以忽略的。

-u同上

-p指出密码,不填默认密码为空。所以密码如果不为空,而你又不没有加上-u,则会提示错误。

回车之后,会提示你输入密码。

mysql -u root -p

登陆root账户。

当然,还可以这样:

mysql -u root -pxxx

这个xxx是我登陆的密码,是文本格式的,如果你不想让别人看到你的密码,还是采用之前的方法。

mysql -u root -p mysql

不仅连接上了mysql服务器,还连接上了数据库mysql。如果不指定mysql数据库的话,会默认登陆mysql数据库中。

2.断开连接

QUIT

断开连接。当然,EXIT或者CTRL+D,也是可以的。

五.创建和删除普通用户

1.创建用户

方法一:用CREATE USER语句

CREATE USER 'user1'@'localhost' IDENTIFIED BY 'user1'

创建名为user1,密码也是user1的用户。

方法二:用INSERT语句

直接将用户的信息添加到mysql.user表中。

具体例子就不给了

方法三:用GRANT语句

GRANT SELECT ON *.* TO 'user3'@'localhost' IDENTIFIED BY 'user3';

创建名为user3,m密码也是user3的用户。

GREAT语句可以为用户授权,比如*.*表示数据库下的所有表。user3对所有表都有查询权限。

2.删除用户

方法一:用DROP USER语句

DROP USER 'user3'@'localhost';

删除用户名为user3的用户

方法二:用DELETE语句

直接将用户的信息从mysql.user中删除

具体例子就不给了。

六.修改密码

1.root用户修改root密码

方法一:使用mysqladmin命令

mysqladmin -u root -p password"root"

将密码改为root.

方法二:用UPDATE

use mysql
update user set Password = PASSWORD('hello') where user='root';

flush privileges;

先选定数据库,然后针对某一个用户(这里是root)设定密码(这里是hello)

最后用 flush privileges;刷新mysql的系统权限相关表

方法三:用SET

SET PASSWORD=PASSWORD('root');

修改root的密码为root。

2.root用户修改普通用户密码

方法一.使用SET语句

SET PASSWORD FOR 'user2'@'localhost'=PASSWORD('user1');

方法二.使用UPDATE

直接修改mysql数据库下的user表。

就不写具体例子了。

方法三:使用GRANT语句

GRANT SELECT ON *.* to 'user2'@'LOCALHOST' identified by 'user2';

3.普通用户修改密码

SET PASSWORD=PASSWORD('test');

七.操作数据库

1.创建数据库

CREATE DATABASE example;

2.删除数据库

DROP DATABASE example;

3.显示数据库

show databases;

4.选择数据库

use mysql;

八.操作表

1.创建表

CREATE TABLE 表名(属性名 数据类型 【完整性约束条件】,

属性名 数据类型 【完整性约束条件】

.

.

.

属性名 数据类型);

例如:

create table text1

(

id INT,

name VARCHAR(20),

SEX BOOLEAN

);

2.显示数据库中的表

show tables;

3.查看表结构

DESCRIBE text1;

4.查看表详细结构

show create table text1;

5.基本查询

select id,name from text1;

从表text中查询字段id和name的信息数据。

6.插入数据

insert into text1(id,name,sex) values(2000,'xiaosan',0);

7.显示表中数据

SELECT * FROM text1;

8.修改记录

update name set id=3000 where name='xiaosan';

9.删除记录

delete from name where id=3000;

10.删除表

drop table 表名

九.数据库的选择


Oracle、DB2、SQL Server:主要应用于比较大的管理系统。SQL Server主要在windows下运行

Access、MysSQL、PostgreSQL:中小型数据库,主要应用于中小型的管理系统,Access只能在windows下运行

复杂度:

Oracle、DB2 > MySQL、PostgreSQL

性能:

Oracle、DB2 > MySQL、PostgreSQL

 bitsCN.com
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

MySQL: The Database, phpMyAdmin: The Management Interface MySQL: The Database, phpMyAdmin: The Management Interface Apr 29, 2025 am 12:44 AM

MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

How to understand DMA operations in C? How to understand DMA operations in C? Apr 28, 2025 pm 10:09 PM

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

How to handle high DPI display in C? How to handle high DPI display in C? Apr 28, 2025 pm 09:57 PM

Handling high DPI display in C can be achieved through the following steps: 1) Understand DPI and scaling, use the operating system API to obtain DPI information and adjust the graphics output; 2) Handle cross-platform compatibility, use cross-platform graphics libraries such as SDL or Qt; 3) Perform performance optimization, improve performance through cache, hardware acceleration, and dynamic adjustment of the details level; 4) Solve common problems, such as blurred text and interface elements are too small, and solve by correctly applying DPI scaling.

macOS vs. Linux: Exploring the Differences and Similarities macOS vs. Linux: Exploring the Differences and Similarities Apr 25, 2025 am 12:03 AM

macOSandLinuxbothofferuniquestrengths:macOSprovidesauser-friendlyexperiencewithexcellenthardwareintegration,whileLinuxexcelsinflexibilityandcommunitysupport.macOS,developedbyApple,isknownforitssleekinterfaceandecosystemintegration,whereasLinux,beingo

Steps to add and delete fields to MySQL tables Steps to add and delete fields to MySQL tables Apr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

See all articles