我们建立数据库一个精髓就是要价廉而又要具有优良的性能。首先我们选择开放的Linux操作系统;同时可以在Linux下应用的数据库系统实在太多了,像Oracle的Oracle 8i、Sybase的 Sybase-ASE for Linux、PostgreSQL以及MySQL。本文要阐述的就是MySQL来基于Linux的数据库管理及应用。
一、 MySQL概述。
可以说这是中小企业网站Linux平台的首选自由数据库系统。它是一个跨平台数据库系统,一个真正
的多用户、多线程的SQL数据库系统,同时是具有客户机/服务器体系结构的分布式数据库管理系统。同时,也是Linux系统中使用最为简单的数据库系统,安装简单、使用简单、管理也简单,且数据库系统的稳定性也很不错。
二、 MySQL安装。
其最新版本可以从http://www.mysql.com获得。跟所有Linux下服务器软件安装类似,一般其安装源
有两类:RPM软件包和源码形式。根据你安装源不同,方法自然有区别,注意两类安装步骤都应以Root登入才行。
1. RPM软件包。
RPM软件包的最小安装:rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
如果只安装客户端:rpm -i MySQL-client-VERSION.i386.rpm
通过以上安装,RPM即将数据放在了“/var/lib/mysql”文件里,同时也在“/etc/rc.d/”里创建适当的入口以便在引导时自动启动服务器。
2. 源代码。
先将其解压:tar -zxvf /tmp/mysql-3.22.21-pc-linux-gnu-i686.tar.gz
./ configure ―――――――-检查相关配置并建立配置
Make
make install ――――――――编译并安装
三、 配置MySQL。
安装完MySQL后, 它将会自动生成两个数据库。一个用于管理用户、主机和服务器数据库权限。另一个是测试数据库(test database)。
1. 建立初始化的MySQL数据库(有些地方也称之为创建授权数据库表)。进入MySQL安装目录,输入以下命令,如果没有任何出错信息显示的话,表示就OK了:
scripts/mysql_install_db
exit
2. 启动服务器:./ /mysql/bin/safe_mysqld &
3. 创建mysql用户,例:useradd - c “ MySQL Administrator” - d /opt/mysql - g users mysql
4. 安装树属权赋给mysql用户,例:chown - R msql.users /opt/msql
四、 测试MySQL。
经过以上几步,数据库应该可以正常使用了,我们可以对其作些基准测试。MySQL里面有一个简单的数据库例子test ,而且它的内部数据库一直保持对权限和帐户的监视,因而可以用此来先运行mysql看看是否可以工作。
1. 如果安装的是RPM软件包,那么程序大都安装在/usr/local/mysql/bin。在此目录下运行客户端程序mysql后,如果出现诸如“Welcome to the MySQL monitor.。。。。“之类的信息,表示MySQL已成功启动。
2. 用show databases命令可以列出安装的数据库清单。
以上两步如都能看到相关信息,表示MySQL完全可以正常工作了。退出MySQL命令:EXIT。
五、 常用命令实例
1. 连接MYSQL
比如我们要连接到远程主机上的MYSQL,并假定远程主机的IP地址为22.33.44.55,用户名为root,密码为1234567,命令格式为:mysql -h22.33.44.55 -uroot –p1234567
而如果是连接到本机上的MYSQL,进入目录 mysqlbin后键入mysql -uroot -p,接着会提示你输密码,正确输入后即可进入MYSQL中了。
2. 增加新用户
增加一个用户user密码为1234567,让他只可以在localhost(本地主机,即MYSQL数据库所在的主机)上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作:grant select,insert,update,delete on mydb.* to user@localhost identified by "1234567";
3. 显示数据库列表:show databases
初始MySQL就两个数据库:mysql和test。如上面“增加新用户”一步就是对mysql库的操作。
4. 备份数据库
进入mysqlbin目录后输入:mysqldump --opt system>backupsys.bbb(将数据库system备份到名为backup sys.bbb的文本文件)
关于此类数据库操作命令还有很多,比如清空表记录delete from、显示数据表结构describe 表名;等等,大家可以参阅有关MySQL的详细教程。

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.

MySQLmanagescharactersetsandcollationsbyusingUTF-8asthedefault,allowingconfigurationatdatabase,table,andcolumnlevels,andrequiringcarefulalignmenttoavoidmismatches.1)Setdefaultcharactersetandcollationforadatabase.2)Configurecharactersetandcollationfor

A MySQL trigger is an automatically executed stored procedure associated with a table that is used to perform a series of operations when a specific data operation is performed. 1) Trigger definition and function: used for data verification, logging, etc. 2) Working principle: It is divided into BEFORE and AFTER, and supports row-level triggering. 3) Example of use: Can be used to record salary changes or update inventory. 4) Debugging skills: Use SHOWTRIGGERS and SHOWCREATETRIGGER commands. 5) Performance optimization: Avoid complex operations, use indexes, and manage transactions.

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.


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

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!