English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MySQL Installation

Die Download-Adressen für MySQL auf allen Plattformen sind: MySQL 下载 . Wählen Sie das aus, was Sie benötigen MySQL Community Server Versionen und zugehörige Plattformen.

注意:Der Installationsprozess erfordert die Aktivierung der Administratorrechte, um installiert zu werden. Andernfalls kann die Installation aufgrund fehlender Berechtigungen nicht durchgeführt werden.

Linux/MySQL auf UNIX installieren

Empfohlen wird auf Linux-Plattformen, RPM-Pakete zu verwenden, um MySQL zu installieren. MySQL AB bietet die folgenden Download-Adressen für RPM-Pakete an:

  • MySQL - MySQL-Server. Diese Option benötigen Sie, es sei denn, Sie möchten nur auf einen MySQL-Server zugreifen, der auf einem anderen Computer läuft.

  • MySQL-client - MySQL-Client-Programme, die zum Verbinden und Verwalten des MySQL-Servers verwendet werden.

  • MySQL-devel - Bibliotheken und Dateien, falls Sie andere MySQL-Client-Anwendungen, wie z.B. Perl-Module, kompilieren möchten, müssen Sie dieses RPM-Paket installieren.

  • MySQL-shared - This software package includes shared libraries (libmysqlclient.so) that some languages and applications need to dynamically load.*) Use MySQL.

  • MySQL-bench - Benchmark and performance testing tools for MySQL database servers.

Before installation, we can check if MySQL is pre-installed on the system:

rpm -qa | grep mysql

If your system is installed, you can choose to uninstall:

rpm -e mysql  // Normal delete mode
rpm -e --nodeps mysql  // Force delete mode, if you are prompted for dependent files when using the above command to delete, you can use this command to force delete them

Install MySQL:

Next, we will install MySQL on Centos7 Use the yum command to install MySQL on the system, note that CentOS 7 The MySQL database has been removed from the default program list in this version, so we need to download the Yum resource package from the official website before installation. The download address is:https://dev.mysql.com/downloads/repo/yum/

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server

Permission settings:

chown mysql:mysql -R /var/lib/mysql

Initialize MySQL:

mysqld --initialize

Start MySQL:

systemctl start mysqld

Check the running status of MySQL:

systemctl status mysqld

注意:If we are starting the mysql service for the first time, the mysql server will first perform initial configuration.

In addition, you can also use MariaDB instead. The MariaDB database management system is a branch of MySQL, mainly maintained by the open source community and licensed under GPL. One of the reasons for developing this branch is that after Oracle Corporation acquired MySQL, there was a potential risk of MySQL being closed source, so the community adopted the branch method to avoid this risk.

The purpose of MariaDB is to be fully compatible with MySQL, including API and command line, making it easy to become a substitute for MySQL.

yum install mariadb-server mariadb

The relevant commands for mariadb database are:

systemctl start mariadb # Start MariaDB
systemctl stop mariadb  #停止 MariaDB
systemctl restart mariadb  #重启 MariaDB
systemctl enable mariadb  #设置开机启动

验证 MySQL 安装

在成功安装 MySQL 后,一些基础表会进行初始化,在服务器启动后,你可以通过简单的测试来验证 MySQL 是否工作正常。

使用 mysqladmin 工具来获取服务器状态:

使用 mysqladmin 命令来检查服务器的版本,在 linux 上该二进制文件位于 /usr/bin 目录,在 Windows 上该二进制文件位于 C:\mysql\bin 。

[root@host]# mysqladmin --version

在 linux 上该命令将输出以下结果,该结果基于你的系统信息:

mysqladmin  Ver 8.23 Distrib 5.0.9-0, for redhat-linux-gnu on i386

如果以上命令执行后未输出任何信息,说明你的 Mysql 未安装成功。

使用 MySQL Client (Mysql 客户端) 执行简单的 SQL 命令

你可以在 MySQL Client (Mysql 客户端) 使用 mysql 命令连接到 MySQL 服务器上,默认情况下 MySQL 服务器的登录密码为空,所以本示例不需要输入密码。

命令如下:

[root@host]# mysql

以上命令执行后会输出 mysql> 提示符,这说明你已经成功连接到 Mysql 服务器上,你可以在 mysql> 提示符执行 SQL 命令:

mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql    |
| test     |
+----------+
2 rows in set (0.13 sec)

Mysql 安装后需要做的

Mysql 安装成功后,默认的 root 用户密码为空,你可以使用以下命令来创建 root 用户的密码:

[root@host]# mysqladmin -u root password "new_password";

现在你可以通过以下命令来连接到 Mysql 服务器:

[root@host]# mysql -u root -p
Passwort eingeben:*******

注意:在输入密码时,密码是不会显示的,你正确输入即可。

Windows 上安装 MySQL

在 Windows 上安装 MySQL 相对来说会比较简单,最新版本可以在 MySQL 下载 中下载中查看(更详细安装:Windows 上安装 MySQL)。

点击 下载 按钮进入下载页面,点击下图中的 不用谢,只开始我的下载。 就可立即下载:

下载完后,我们将 zip 包解压到相应的目录,这里我将解压后的文件夹放在 C:\web\mysql-8.0.11 下。

接下来我们需要配置下 MySQL 的配置文件

打开刚刚解压的文件夹 C:\web\mysql-8.0.11 ,在该文件夹下创建 my.ini 配置文件,编辑 my.ini 配置以下基本信息:

[client]
# 设置mysql客户端默认字符集
default-character-set=utf8
 
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\\web\\mysql-8.0.11
# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错
# datadir=C:\\web\\sqldata
# 允许最大连接数
max_connections=20
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

接下来我们来启动下 MySQL 数据库:

以管理员身份打开 cmd 命令行工具,切换目录:

cd C:\web\mysql-8.0.11\bin

初始化数据库:

mysqld --initialize --console

执行完成后,会输出 root 用户的初始默认密码,如:

...
2018-04-20T02:35:05.464644Z 5 [注意] [MY-010454】 [Server] 一个临时的密码已为 root@localhost: APWCY 生成5ws&hjQ
...

APWCY5ws&hjQ 就是初始密码,后续登录需要用到,你也可以在登陆后修改密码。

输入以下安装命令:

mysqld install

启动输入以下命令即可:

net start mysql

注意: 在 5.7 需要初始化 data 目录:

cd C:\web\mysql-8.0.11\bin 
mysqld --initialize-insecure

初始化后再运行 net start mysql 即可启动 mysql。

MySQL anmelden

Wenn der MySQL-Dienst bereits läuft, können wir über den integrierten Client des MySQL-Tools auf die MySQL-Datenbank zugreifen. Öffnen Sie zunächst den Befehlszeilen-Editor und geben Sie den folgenden Befehl in folgendem Format ein:

mysql -h Hostname -u Benutzername -p

Parameterbeschreibung:

  • -h : Gibt den Hostnamen des MySQL-Servers an, auf dem der Client angemeldet werden soll. Für den lokalen Zugriff (localhost oder 127.0.0.1) Dieses Parameter kann weggelassen werden;

  • -u : Benutzername für die Anmeldung;

  • -p : Der Server wird eine Passwort verwendet, um sich anzumelden. Wenn der Benutzername und das Passwort leer sind, kann diese Option ignoriert werden.

Wenn wir auf die MySQL-Datenbank unseres Computers zugreifen möchten, müssen wir nur den folgenden Befehl eingeben:

mysql -u root -p

Drücken Sie die Eingabetaste, um zu bestätigen. Wenn die Installation korrekt ist und MySQL läuft, erhalten Sie die folgende Antwort:

Passwort eingeben:

Wenn das Passwort vorhanden ist, geben Sie das Passwort ein, um sich anzumelden. Wenn es nicht vorhanden ist, drücken Sie einfach die Eingabetaste, um sich anzumelden. Nach einer erfolgreichen Anmeldung werden Sie die Meldung Welcome to the MySQL monitor... sehen.

Dann wird der Befehlszeilen-Editor immer mit einem blinkenden Cursor im Format mysq> warten, um Befehle einzugeben. Geben Sie ein: exit oder quit Abmelden.