2.安装配置

予早 2025-08-31 14:59:18
Categories: Tags:

安装

install for windows

https://www.mysql.com/

img

https://dev.mysql.com/

img

https://dev.mysql.com/downloads/

img

https://dev.mysql.com/downloads/installer/

img

msi

img

img

一个用于VS的插件不满足安装条件,可以使用自定义安装。

img

img

img

这个各个工具的路径都可选

img

img

img

img

img

img

img

img

img

img

img

Mysql_123456

img

img

img

img

img

img

img

img

img

img

install for linux, singleton

节点目录

mkdir -p /usr/local/mysql/singleton/data
mkdir -p /usr/local/mysql/singleton/log
mkdir -p /usr/local/mysql/singleton/sql # 存放sql

配置文件my.cnf

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/singleton/data

socket=/usr/local/mysql/singleton/mysqld.sock
pid-file=/usr/local/mysql/singleton/mysqld.pid

log_error=/usr/local/mysql/singleton/log/error.log
log_bin=/usr/local/mysql/singleton/log/bin_log

lower_case_table_names = 1

初始化

/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/singleton/my.cnf --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/singleton/data --user=root &
cat /usr/local/mysql/singleton/log/error.log

[!NOTE]

初始化时可能会提示没有安装libaio.so.1

sudo apt update
# Ubuntu 24.04 中包名为 libaio1t64
sudo apt install libaio1t64
# 创建软连接兼容旧使用方式
sudo ln -s /lib/x86_64-linux-gnu/libaio.so.1t64 /lib/x86_64-linux-gnu/libaio.so.1

启动

/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/singleton/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/singleton/data --user=root &

注:上述defaults-file一定要放在前面,否则会使用默认配置

登陆并修改密码

/usr/local/mysql/bin/mysql -uroot -P 3306 -S /usr/local/mysql/singleton/mysqld.sock -p
1Heh(L3X/i=-
ALTER USER USER() IDENTIFIED BY 'mYsql123456_';
use mysql;
update user set host='%' where user='root';
FLUSH PRIVILEGES;

关闭

/usr/local/mysql/bin/mysqladmin -h127.0.0.1 -uroot -P3306 -p shutdown

注:MySQL可以单体多实例安装,源码安装、二进制安装、包管理器安装

Ref

https://zhuanlan.zhihu.com/p/188416607