MySQL 的安装

Installing MySQL on Unix/Linux Using Generic Binaries

版本

Linux 5.7.17

依赖

CentOS

yum install libaio libaio-devel

Ubuntu

apt install libaio1 libaio-dev

准备简单配置文件

删除多余文件

rm -rf /etc/my.cnf /etc/my.cnf.d /etc/mysql && mkdir -p /etc/mysql

准备配置文件

vim /etc/mysql/my.cnf

复制如下内容

[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306

# Path to installation directory. All paths are usually resolved relative to this
basedir="/usr/local/mysql"

# Path to the database root
datadir="/usr/local/mysql/data"

# PID file name
pid-file = mysqld.pid

# The default character set that will be used when a new schema or table is created and no character set is defined
character-set-server=utf8mb4

# encode
collation-server = utf8mb4_unicode_ci

init_connect = 'SET collation_connection=utf8mb4_unicode_ci'

init_connect = 'SET NAMES utf8mb4'

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES"

# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="mysqld.log"
slow-query-log=1
slow_query_log_file="mysqld-slow.log"

# 超过5秒的查询才被记为慢查询,建议根据您的环境将long_query_time调短。通常建议设为1-5秒。
long_query_time=5

# Error Logging
log-error="mysqld.err"

# Server Id
#server-id=1

安装

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize-insecure --user=mysql
bin/mysql_ssl_rsa_setup
cp support-files/mysql.server /etc/init.d/mysqld

设置环境变量

cp /etc/profile /etc/profile.backup
echo "# MySQL PATH" >> /etc/profile
echo "export PATH=$""PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile

建立服务文件

vim /lib/systemd/system/mysqld.service

复制如下内容

[Unit]

Description=MySQL Service

After=network.target

[Service]

Type=forking

ExecStart=/etc/init.d/mysqld start

ExecReload=/etc/init.d/mysqld restart

ExecStop=/etc/init.d/mysqld  stop

PrivateTmp=false

[Install]

WantedBy=multi-user.target

以754的权限保存在目录

chmod 745 /lib/systemd/system/mysqld.service

必须先启动服务

systemctl start mysqld.service

然后设置密码

mysqladmin -u root -p password '你的密码'
Enter password:
# 因为我们是无密码初始化,直接回车即可。
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

重启服务生效

systemctl restart mysqld.service

Installing MySQL on Microsoft Windows Using a noinstall ZIP Archive

版本

Windows 5.7.17

本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!