zoukankan      html  css  js  c++  java
  • mysql8.0.22在centos7.6下的简单安装

    如果想把mysql安装得好一些,则严重推荐使用压缩包来安装。

    一般情况下,现在大部分的服务器都是x86-64,少数是arm架构的。

    选择合适的版本,下载即可。

    本文中,使用的是 mysql-8.0.22-el7-x86_64.tar.gz (这对centos7的)

    为了便于管理,个人推荐的目录

    /soft/mysql/program  --放myql程序文件

    /soft/mysql/config     --放mysql的配置文件,配置文件可以随意命名,例如my.ini,my.cnf,my.config之类都无所谓

    当然也可以直接使用默认的/etc/my.cnf 路径

    下面是大概的步骤:

    1.解压文件

    2.写好my.cnf

    3.初始化

    4.启动服务,修改root密码

    5.把mysql配置为服务,以便自动启动

    这里稍微说下2,3.

    步骤2:写my.cnf,重点几个:

    1)字符集

    2)数据目录

    3)端口

    4)是否使用root运行(很多时候,我们就用root执行了)

    5)密码验证方式

    6)是否忽略大小写

    7)是否关比bin_log(如果不复制,这个可以节约时间)

    8)日志目录

    下面是my.cnf的配置例子:

    [client]
    port=3318
    
    [mysql]
    no-beep
    default-character-set=UTF8MB4
    
    [mysqld]
    user=root
    skip-log-bin
    port=3318
    #不区分大小写(linux设置,windows不设置。linux必须初始化的时候设置)
    lower_case_table_names=1
    # 程序路径
    basedir="/soft/mysql-8.0.22-el7-x86_64"
    
    # 数据库实例根数据路径
    datadir=/data/mysql
    
    # 创建数据库和表的默认字符集
    character-set-server=UTF8MB4
    
    # 默认存储引擎
    default-storage-engine=INNODB
    
    
    # General and Slow logging.
    log-output=FILE
    slow-query-log=0
    bulk_insert_buffer_size=32M
    
    # Error 日志
    log-error="mysql.err"
     
    # 最大并发会话
    max_connections=500
    
    # 所有线程可以允许打开的表数量
    table_open_cache=1200
    
    # Maximum size for internal (in-memory) temporary tables. If a table
    # grows larger than this value, it is automatically converted to disk
    # based table This limitation is for a single table. There can be many
    # of them.
    # 内存临时表大小--如果有许多需要临时表的查询,而且这些临时表都挺大的,可以考虑设置大一些
    # 当然前提,是您相对比较阔绰,可以有许多内存
    tmp_table_size=32M
    
    # How many threads we should keep in a cache for reuse. When a client
    # disconnects, the client's threads are put in the cache if there aren't
    # more than thread_cache_size threads from before.  This greatly reduces
    # the amount of thread creations needed if you have a lot of new
    # connections. (Normally this doesn't give a notable performance
    # improvement if you have a good thread implementation.)
    thread_cache_size=10
    
    
    # Size of the buffer used for doing full table scans of MyISAM tables.
    # Allocated per thread, if a full scan is needed.
    read_buffer_size=0
    
    read_rnd_buffer_size=0
    
    #*** INNODB Specific options ***
    # innodb_data_home_dir=0.0
    
    # Use this option if you have a MySQL server with InnoDB support enabled
    # but you do not plan to use it. This will save memory and disk space
    # and speed up some things.
    # skip-innodb
    
    # If set to 1, InnoDB will flush (fsync) the transaction logs to the
    # disk at each commit, which offers full ACID behavior. If you are
    # willing to compromise this safety, and you are running small
    # transactions, you may set this to 0 or 2 to reduce disk I/O to the
    # logs. Value 0 means that the log is only written to the log file and
    # the log file flushed to disk approximately once per second. Value 2
    # means the log is written to the log file at each commit, but the log
    # file is only flushed to disk approximately once per second.
    #谨慎修改这个参数
    innodb_flush_log_at_trx_commit=1
    
    # The size of the buffer InnoDB uses for buffering log data. As soon as
    # it is full, InnoDB will have to flush it to disk. As it is flushed
    # once per second anyway, it does not make sense to have it very large
    # (even with long transactions).
    innodb_log_buffer_size=128m
    
    #建议开启严谨模式
    innodb_strict_mode=on
    
    
    #密码验证方式
    default_authentication_plugin=mysql_native_password

    步骤3:初始化

    如果使用专有的mysql用户启动配置(这是推荐的)

    bin/mysqld --defaults-file=/opt/mysql/mysql/etc/my.cnf  --initialize  --user=mysql

    如果想用root且修改配置文件路径,则可以修改为

    bin/mysqld --defaults-file=/data/mysql/config/my.cnf  --initialize  --user=root

    安装为服务

    有时候不一定按照下面就可以安装为服务,要看系统的情况。

    注意:如果修改了路径则必须修改mysql.server文件

    mysql.server一般在support-files下

    以下是一般需要修改的片段:

    # If you change base dir, you must also change datadir. These may get
    # overwritten by settings in the MySQL configuration files.

    basedir=/soft/mysql-8.0.22-el7-x86_64
    datadir=/data/mysql

    复制启动文件  cp mysql.server /etc/init.d/mysqld

    赋予可执行权限:# chmod +x /etc/init.d/mysqld

    添加为服务:# chkconfig --add mysqld

    之后可以使用 systemctl start/stop/status mysqld

    也可以直接使用mysql.server start/stop等

    最后,申明下,以上的配置仅仅能够满足一般的开发,要想满足高性能的配置,远远不够。

    作为一个mysql dba,必须掌握以下知识:

    1)mysql 开发

    2)  linux配置

    3) mysql 配置

    4)操作系统、网络

  • 相关阅读:
    WPF自定义RoutedEvent事件代码段
    微信聊天和通讯录按钮样式
    【转】c#、wpf 字符串,color,brush之间的转换
    模块式开发
    通过属性进行浅拷贝
    【转】string.Format对C#字符串格式化
    酷学习笔记——前言
    C# 连蒙带骗不知所以然的搞定USB下位机读写
    C# Ioc、DI、Unity、TDD的一点想法和实践
    虹软人脸识别速度测试征集
  • 原文地址:https://www.cnblogs.com/lzfhope/p/14057516.html
Copyright © 2011-2022 走看看