MySQL YUN安装方式

39 阅读2分钟

从官网下载

地址: dev.mysql.com/downloads/r… 寻找合适的版本,我的系统的麒麟银河V10 ,我选择的是 linux 7 ,安装成功。

image.png

安装的步骤

  1. 把下载的文件上传到服务器
  2. 安装yum源
  3. 安装MySQL
# 安装yum源 
yum localinstall mysql84-community-release-el7-2.noarch.rpm

# 安装MySQL 
yum install mysql-community-server

image.png

image.png

启动与配置

# 启动MySQL
 systemctl start mysqld
 
# 查看启动是否成功
systemctl status mysqld

# 设置开机启动
systemctl enable mysqld

# 取消开机启动
systemctl disable mysqld

获取初始化密码

sudo grep 'temporary password' /var/log/mysqld.log

使用上面查看到的密码设置初始化密码

    sudo mysql_secure_installation

配置远程登录

     --  # 创建账号
    CREATE USER 'remote_user'@'%' IDENTIFIED BY 'your_strong_password';

    # 授权登录
    GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;

   -- 修改当前登录用户的密码 
   ALTER USER USER() IDENTIFIED BY '123456';
   -- 修改指定用户的密码
   ALTER USER 'admin'@'%' IDENTIFIED BY 'MyNewPass@2024';

    -- # 刷新授权,立即生效
    FLUSH PRIVILEGES;

配置优化

让MySQL获取更高的性能, vim /etc/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

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

bind-address = 0.0.0.0
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

# Performance Tuning for 4 Cores, 8GB RAM
innodb_buffer_pool_size = 5G

# 使用新的 redo log 配置(替代旧的 innodb_log_file_size 和 innodb_log_files_in_group)
innodb_redo_log_capacity = 2G

innodb_buffer_pool_instances = 8
innodb_thread_concurrency = 8
innodb_file_per_table = ON
innodb_log_buffer_size = 256M

max_connections = 500
max_allowed_packet = 64M

# 24小时空闲连接 就会断开
interactive_timeout = 86400
wait_timeout = 86400

# 禁用主机缓存(替代 --skip-host-cache)
host_cache_size = 0

常用的命令

-- 查看最大的连接数
SHOW VARIABLES LIKE 'max_connections';

-- 查看当前超时设置
SHOW VARIABLES LIKE 'wait_timeout';
SHOW VARIABLES LIKE 'interactive_timeout';

-- 设置密码策略 为低级别, 永久生效,开放环境设置简单的密码时候 可以用一下
SET PERSIST validate_password.policy = 'LOW';
-- 查看密码强度
SHOW VARIABLES LIKE '%validate_password%'