MySQL installation and environmentconfiguration

详细介绍MySQL installationmethod and environmentconfiguration

1. MySQL Introduction

MySQL is a open-source relationships型datalibrarymanagementsystem, 由Oracle公司Development and maintenance. 它 is 世界 on 最流行 datalibrarysystem之一, 被widely used in各种规模 application程序in, from 个人project to big 型企业级application.

MySQL 主要特点including:

  • open-source免费
  • 跨平台support
  • high performance
  • reliability high
  • 易于using and management
  • 丰富 functions and tool

2. Windows systeminstallation MySQL

2.1 under 载 MySQL installationpackage

  1. 访问MySQL 官方 under 载页面
  2. 选择适合你system installationpackageversion
  3. under 载 MySQL Installer or MySQL Community Server

2.2 runinstallation程序

  1. 双击 under 载 installationfile, 启动installation向导
  2. 选择installationclass型 (推荐选择 "Developer Default")
  3. 按照向导提示completioninstallation过程
  4. in configuration步骤in设置 root userpassword
  5. completioninstallation after , 启动 MySQL service

2.3 verificationinstallation

打开commands提示符, 输入以 under commandsverification MySQL is 否installation成功:

mysql --version

using root userlogin MySQL:

mysql -u root -p

输入你设置 password, 成功login after 会看 to MySQL commands行提示符.

3. macOS systeminstallation MySQL

3.1 using Homebrew installation

such as果你 system已经installation了 Homebrew, 可以using以 under commandsinstallation MySQL:

brew install mysql

启动 MySQL service:

brew services start mysql

3.2 using DMG installationpackageinstallation

  1. 访问MySQL 官方 under 载页面
  2. under 载 macOS version DMG installationpackage
  3. 双击installationpackage, 按照向导completioninstallation
  4. in system偏 good 设置in启动 MySQL service

3.3 verificationinstallation

打开终端, 输入以 under commandsverification MySQL is 否installation成功:

mysql --version

using root userlogin MySQL:

mysql -u root -p

4. Linux systeminstallation MySQL

4.1 Ubuntu/Debian system

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation

启动 MySQL service:

sudo systemctl start mysql
sudo systemctl enable mysql

4.2 CentOS/RHEL system

sudo yum update
sudo yum install mysql-server
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo mysql_secure_installation

4.3 verificationinstallation

输入以 under commandsverification MySQL is 否installation成功:

mysql --version

using root userlogin MySQL:

sudo mysql -u root

5. MySQL configurationfile

5.1 configurationfile位置

  • Windows: C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
  • macOS: /usr/local/mysql/my.cnf or /etc/my.cnf
  • Linux: /etc/mysql/my.cnf or /etc/my.cnf

5.2 常用configuration项

[mysqld]
# 端口号
port = 3306

# dataTable of Contents
datadir = /var/lib/mysql

# 字符集
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

# 最 big connections
max_connections = 100

# logfile
log-error = /var/log/mysql/error.log

#  slow querylog
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2

6. MySQL environmentvariableconfiguration

6.1 Windows system

  1. right 键点击 "此电脑", 选择 "property"
  2. 点击 "advancedsystem设置"
  3. 点击 "environmentvariable"
  4. in "systemvariable" in找 to "Path", 点击 "编辑"
  5. 添加 MySQL bin Table of Contentspath, 例such as: C:\Program Files\MySQL\MySQL Server 8.0\bin
  6. 点击 "确定" 保存设置

6.2 macOS/Linux system

编辑 ~/.bashrc or ~/.zshrc file, 添加以 under in 容:

export PATH="/usr/local/mysql/bin:$PATH"

使configuration生效:

source ~/.bashrc
or
source ~/.zshrc

7. commonissues and solution

7.1 忘记 root password

such as果忘记了 MySQL root password, 可以按照以 under 步骤reset:

  1. 停止 MySQL service
  2. 以跳过authorization表 方式启动 MySQL
  3. reset root password
  4. 重启 MySQL service

7.2 端口占用issues

such as果 MySQL 启动失败, 可能 is 因 for 端口 3306 被占用. 可以using以 under commands查看端口占用circumstances:

netstat -tlnp | grep 3306

modifyconfigurationfilein 端口号, or 停止占用该端口 process.

7.3 service启动失败

check MySQL errorlog, 通常位于:

  • Windows: C:\ProgramData\MySQL\MySQL Server 8.0\Data\主机名.err
  • Linux: /var/log/mysql/error.log

实践练习

  1. in 你 system on installation MySQL
  2. configuration MySQL environmentvariable
  3. 启动 MySQL service
  4. using root userlogin MySQL
  5. creation一个 new datalibrary and user
  6. modify MySQL configurationfile, 调整最 big connections for 200