如何安装mysql

tech2023-01-22  114

如何安装mysql

In the first of a series of MySQL articles, we will discover how easy it is to install the database system on your development PC.

在一系列MySQL文章的第一篇中,我们将发现在开发PC上安装数据库系统非常容易。

为什么选择MySQL? (Why MySQL?)

MySQL is undoubtedly the most popular and widely-used open source database:

无疑,MySQL是最流行和使用最广泛的开源数据库:

it is simple to set up and use

易于设置和使用 it is recognised as one of the fastest database engines

它被公认为最快的数据库引擎之一 most Linux (and many Windows-based) web hosts offer MySQL

大多数Linux(以及许多基于Windows的)网络主机都提供MySQL MySQL is closely integrated with PHP, which makes it an ideal candidate for many web applications.

MySQL与PHP紧密集成,这使其成为许多Web应用程序的理想选择。

为什么要在本地安装MySQL? (Why Install MySQL Locally?)

Installing MySQL on your development PC allows you to safely create and test a web application without affecting the data or systems on your live website (I will cover installing a web server and PHP in a later articles).

在开发PC上安装MySQL可使您安全地创建和测试Web应用程序,而不会影响实时网站上的数据或系统(我将在以后的文章中介绍如何安装Web服务器和PHP)。

This article describes how to install MySQL on Windows, but versions are available for Mac, Linux, and several other operating systems.

本文介绍了如何在Windows上安装MySQL,但是Mac,Linux和其他几种操作系统都可以使用这些版本。

多合一套餐 (All-in-One packages)

There are some excellent all-in-one Windows distributions that contain Apache, PHP, MySQL and other applications in a single installation file, e.g. XAMPP, WampServer and Web.Developer. There is nothing wrong with using these packages, but manually installing MySQL will help you learn more about the system and give you more control.

有一些出色的多合一Windows发行版,它们在单个安装文件中包含Apache,PHP,MySQL和其他应用程序,例如XAMPP , WampServer和Web.Developer 。 使用这些软件包没有错,但是手动安装MySQL将帮助您了解有关系统的更多信息并给予您更多控制权。

MySQL安装向导 (The MySQL Installation Wizard)

An excellent .msi installation wizard is available for MySQL. The wizard creates the my.ini configuration file and installs MySQL as a service. This option is certainly recommended for novice users or perhaps those installing MySQL for the first time.

一个出色的.msi安装向导可用于MySQL。 该向导将创建my.ini配置文件,并将MySQL作为服务安装。 对于新手用户或首次安装MySQL的用户,无疑建议使用此选项。

手动安装 (Manual Installation)

Manual installation offers several benefits:

手动安装具有以下优点:

backing up, reinstalling, or moving databases can be achieved in seconds (see 8 Tips for Surviving PC Failure)

可以在几秒钟内完成备份,重新安装或移动数据库的操作(请参阅PC失败后的8条提示 )

you have more control over how and when MySQL starts

您可以更好地控制MySQL启动的方式和时间 you can install MySQL anywhere, such as a portable USB drive (useful for client demonstrations).

您可以在任何地方安装MySQL,例如便携式USB驱动器(可用于客户端演示)。

Step 1: download MySQL Download MySQL from dev.mysql.com/downloads/. Follow MySQL Community Server, Windows and download the “Without installer” version.

步骤1:下载MySQL从dev.mysql.com/downloads/下载MySQL。 跟随MySQL Community Server , Windows并下载“无安装程序”版本。

As always, virus scan the file and check the its MD5 checksum using a tool such as fsum.

与往常一样,病毒扫描文件并使用诸如fsum之类的工具检查其MD5校验和。

Step 2: extract the files We will install MySQL to C:mysql, so extract the ZIP to your C: drive and rename the folder from “mysql-x.x.xx-win32” to “mysql”.

步骤2:提取文件我们将MySQL安装到C:mysql,因此将ZIP提取到C:驱动器,并将文件夹从“ mysql-xxxx-win32”重命名为“ mysql”。

MySQL can be installed anywhere on your system. If you want a lightweight installation, you can remove every sub-folder except for bin, data, scripts and share.

MySQL可以安装在系统上的任何位置。 如果要进行轻量级安装,则可以删除除bin,数据,脚本和共享以外的所有子文件夹。

Step 3: move the data folder (optional) I recommend placing the data folder on another drive or partition to make backups and re-installation easier. For the purposes of this example, we will create a folder called D:MySQLdata and move the contents of C:mysqldata into it.

步骤3:移动数据文件夹(可选)我建议将数据文件夹放置在另一个驱动器或分区上,以使备份和重新安装更加容易。 出于本示例的目的,我们将创建一个名为D:MySQLdata的文件夹,并将C:mysqldata的内容移入其中。

You should now have two folders, D:MySQLdatamysql and D:MySQLdatatest. The original C:mysqldata folder can be removed.

现在,您应该有两个文件夹,D:MySQLdatamysql和D:MySQLdatatest。 原始的C:mysqldata文件夹可以删除。

Step 4: create a configuration file MySQL provides several configuration methods but, in general, it is easiest to to create a my.ini file in the mysql folder. There are hundreds of options to tweak MySQL to your exact requirements, but the simplest my.ini file is:

第4步:创建配置文件 MySQL提供了几种配置方法,但通常,最简单的方法是在mysql文件夹中创建my.ini文件。 有数百种选项可将MySQL调整为您的确切要求,但最简单的my.ini文件是:

[mysqld] # installation directory basedir="C:/mysql/" # data directory datadir="D:/MySQLdata/"

(Remember to change these folder locations if you have installed MySQL or the data folder elsewhere.)

(如果您已经在其他位置安装了MySQL或数据文件夹,请记住要更改这些文件夹的位置。)

Step 5: test your installation The MySQL server is started by running C:mysqlbinmysqld.exe. Open a command box (Start > Run > cmd) and enter the following commands:

步骤5:测试安装通过运行C:mysqlbinmysqld.exe启动MySQL服务器。 打开命令框(开始>运行> cmd),然后输入以下命令:

cd mysqlbin mysqld

This will start the MySQL server which listens for requests on localhost port 3306. You can now start the MySQL command line tool and connect to the database. Open another command box and enter:

这将启动MySQL服务器,该服务器在本地主机端口3306上侦听请求。您现在可以启动MySQL命令行工具并连接到数据库。 打开另一个命令框,然后输入:

cd mysqlbin mysql -u root

This will show a welcome message and the mysql> prompt. Enter “show databases;” to view a list of the pre-defined databases.

这将显示欢迎消息和mysql>提示符。 输入“显示数据库;” 查看预定义数据库的列表。

Step 6: change the root password The MySQL root user is an all-powerful account that can create and destroy databases. If you are on a shared network, it is advisable to change the default (blank) password. From the mysql> prompt, enter:

步骤6:更改root密码 MySQL root用户是一个功能强大的帐户,可以创建和销毁数据库。 如果您在共享网络上,建议更改默认(空白)密码。 在mysql>提示符下,输入:

UPDATE mysql.user SET password=PASSWORD("my-new-password") WHERE User='root'; FLUSH PRIVILEGES;

You will be prompted for the password the next time you start the MySQL command line.

下次启动MySQL命令行时,系统将提示您输入密码。

Enter “exit” at the mysql> prompt to stop the command line client. You should now shut down MySQL with the following command:

在mysql>提示符下输入“ exit”以停止命令行客户端。 现在,您应该使用以下命令关闭MySQL:

mysqladmin.exe -u root shutdown

Step 7: Install MySQL as a Windows service The easiest way to start MySQL is to add it as a Windows service. From a command prompt, enter:

步骤7:将MySQL安装为Windows服务启动MySQL的最简单方法是将其添加为Windows服务。 在命令提示符下,输入:

cd mysqlbin mysqld --install

Open the Control Panel, Administrative Tools, then Services and double-click MySQL. Set the Startup type to “Automatic” to ensure MySQL starts every time you boot your PC.

打开控制面板,管理工具,然后打开服务,然后双击MySQL。 将启动类型设置为“自动”,以确保每次启动PC时都启动MySQL。

Alternatively, set the Startup type to “Manual” and launch MySQL whenever you choose using the command “net start mysql”.

或者,将启动类型设置为“手动”,并在每次使用命令“ net start mysql”选择时启动MySQL。

Note that the Windows service can be removed using:

请注意,可以使用以下方法删除Windows服务:

cd mysqlbin mysqld --remove

See also:

也可以看看:

MySQL: the Pros and Cons of MyISAM Tables

MySQL:MyISAM表的优缺点

MySQL: the Pros and Cons of InnoDB Tables

MySQL:InnoDB表的优缺点

How to Use MySQL Foreign Keys for Quicker Database Development

如何使用MySQL外键来加快数据库开发

How to Install Apache

如何安装Apache

How to Install PHP

如何安装PHP

翻译自: https://www.sitepoint.com/how-to-install-mysql/

如何安装mysql

相关资源:jdk-8u281-windows-x64.exe
最新回复(0)